Variables for colors in interface builder - xcode

I have a project that I need to change overall color themes in the app. A lot of my UI elements are built through Interface Builder in Xcode 6.1. I need to set colors as variables in interface builder, so if I set a preprocessor telling the app to use a certain scheme then the colors will change in interface builder. Is this even possible?

I'm not aware of any way to do this with interface builder, however there is a way that you can set appearance properties in code for many IOS UI elements that will then apply globally. As an example see the following snippet of code:
UIToolbar.appearance().tintColor = UIColor.whiteColor()
UIToolbar.appearance().barTintColor = UIColor.blackColor()
UITableView.appearance().separatorColor = UIColor.grayColor()
UITableView.appearance().sectionIndexColor = UIColor.grayColor();
UINavigationBar.appearance().tintColor = UIColor.blueColor()
UINavigationBar.appearance().barTintColor = UIColor.blackColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
The code sets a the default tint and bar color for all the UIToolbars, separator and section index colors for all UITableViews, and appearance properties for all the UINavigation views in my app..
You could use #if to set the appearance differently depending on the environment variables set in the compiler.
If you want to find out more about how this works Id suggest reading Apples documentation on UIAppearance properties here:
UIAppearance Documentation

Color variables are awesome, I wish xcode had this too.
Turns out you can add a color variables feature.
This xcode plugin, called Suggested Colors, let's you build and use a palette of colors in Interface Builder. It uses a plist file, So I think you could read that in code and have a color palette shared between code and IB this way. Looks promising. Unfortunately, doesn't seem to work on xcode 6.3.2. Hope it gets fixed.

Related

VCL TForm::TransparentColor not working with custom appearance style

I tried to make one of my TForms decendants transparent. The form is floating above (Z-wise) another application (not mine) and all that should be seen are a few controls "floating in the air". These controls provide some extra functionality and information that I'm missing. I have set
this->TransparentColorValue = this->Color;
this->TransparentColor = true;
This didn't have any visible effect, even if I set these at runtime to make sure that whatever Color the form has, the TransparentColor should be the same. I also tried explicitly setting the Color to clBlack first to make it as simple as possible.
My application also uses a Custom Style (High-DPI Optimized or "normal" doesn't seem to make a difference) and I'm now thinking that it's not possible to use one of these styles and make one of the forms transparent.
If I remove the custom style and use the default "Windows" style, the form becomes transparent and behaves just like I want. I can "click through" my transparent form to interact with the application behind it.
I tried SetWindowTheme(this->Handle, nullptr, L""); on the form in question but that didn't change its appearance either. I also wanted to try SetWindowTheme(this->Handle, nullptr, L"The CLSID for Windows"); but I couldn't find the CLSID for the "Windows" style.
Changing the style using the TStyleManager a'la std::make_unique<TStyleManager>()->SetStyle(L"Windows"); changes the style of the whole application.
I've enabled Runtime Themes and set DPI Awareness to Per Monitor v2.
Is my suspicion correct or is there a way to use a Custom Style and still have one form in an app transparent? If a moderate amount of WinAPI tinkering is required to do it, I'm happy with that too.
C++ Builder Community 10.4

How to set VCL custom style "Light" on owner drawn TColorButton?

I am modifying my windows desktop VCL project (windows) style to custom style "Light".
I am having trouble to modify an owner drawn TColorButton Delphi component (
http://delphi.about.com/od/vclwriteenhance/l/aa061104a.htm ) to "Light" custom style.
When I set my project style to custom style "Light", TColorButton acts like a normal TButton (colour can't be modify) with Light style. I understood after gone through other questions on this site that, I should unset style elements client (i.e StyleElemets.seClient := false) to change back ground colour. But, it resets the style of delphi component TColorButton to standard windows style.
Could you please suggest me, how to overcome above issue ?
VCL Light custom style has a different back ground colour when mouse over/onclick event on the button. Is it possible to get hex value of colour?
Thanks in advance for any help you are able to provide.

How to set the default writing direction for NSTextView?

I'm trying to set up a text view that a user can type Hebrew text into from right-to-left. Currently it defaults to a left-to-right text direction, which the user can manually change by right-clicking and selecting "Writing Direction > Right to Left", but what I need is for the text view to always default to this, without requiring the user to set it manually.
There's an option for setting this in Interface Builder, which is always ignored when I build and run my app.
I would be fine setting it from code, but I can't figure out how to use the method that looks like the closest thing to what I need:
hebrewTextView.setBaseWritingDirection(NSWritingDirection.RightToLeft, range: <#NSRange#>)
The range is stumping me. If it takes a range can this be the method I need? Wouldn't the default behavior of a field be independent of any range of text?
Is there a way to set the default writing direction for a NSTextView? Can this be done from the storyboard/interface builder, or from code? If setBaseWritingDirection is the method for this, what is the range value for and how would I set it for a field that is initially empty?
NSTextView inherits from NSText. NSText has a baseWritingDirection property. Try setting that:
hebrewTextView.baseWritingDirection = NSWritingDirection.RightToLeft
It also inherits the action method makeBaseWritingDirectionRightToLeft() from NSResponder, which presumably what the contextual menu uses. So, you could call that.
If neither of those works, you can set the text view's defaultParagraphStyle to one whose baseWritingDirection is right-to-left:
var style = hebrewTextView.defaultParagraphStyle.mutableCopy() as! NSMutableParagraphStyle
style.baseWritingDirection = NSWritingDirection.RightToLeft
hebrewTextView.defaultParagraphStyle = style

Setting default color in Windows Forms

I'm creating a simple GUI using Powershell and Windows Forms for a set of scripts I have written.
I've generated a bunch of buttons in the GUI and I'm currently in the process of adding styles to my buttons.
$Button1 = New-Object System.Windows.Forms.Button
Is there anyway to set the below set of lines as a global/default setting of sorts for all buttons?
$Button1.Cursor = [System.Windows.Forms.Cursors]::Hand
$Button1.BackColor = '#CCCC99'
$Button1.Font = New-Object System.Drawing.Font("Verdana",10,[System.Drawing.FontStyle]::Bold)
To give you an idea, what I'm doing now is adding the block of text for every button.
$Button1.BackColor = '#CCCC99'
$Button2.BackColor = '#CCCC99'
$Button3.BackColor = '#CCCC99'
etc...
I'm pretty sure there's a better and more efficient way to do this. Can anyone point me to the right direction?
I expect all buttons to look pretty much the same.
Thanks in advance.
You could loop through all of the buttons after they have been created and set their properties, like TheMadTechnician suggests…
But there is a better way. Think object-oriented programming. You have a Button class, and you want to change its default properties. In fact, you want all of your buttons to have those new properties. So really, what you want is a custom control that is like a button but slightly different.
Well, what do you know? There's a linguistic way to express that:
public class MyBeautifulButton : System.Windows.Forms.Button
{
public MyBeautifulButton()
{
// Set default properties here...
}
}
You can even go one fancier and override the specific properties, setting the appropriate attributes, to change their default values.
Then, instead of creating System.Windows.Forms.Button objects in your PowerShell code, you will create MyBeautifulButton objects.
Although I must say that I don't think the result will be terribly beautiful. The BackColor property of a button is one of those that I don't think should have ever been provided. Button controls are designed to be drawn using the system theme, which specifies the colors for you. It also allows the users to customize the colors as desired. Application-specified colors usually result in a visually jarring and downright ugly UI. Don't let your app stick out like a sore thumb. Buttons are utility controls. Consistency is key. Remember that GUI applications are not web pages.
Why not just apply that to all buttons after you add them to the form? Something along the lines of:
$MyForm.Controls | Where{$_.GetType().Name -eq "Button"} | ForEach{$_.BackColor = '#CCCC99'}

How to add a NSColorPicker to the application's main window?

I'm building an application to generate an array of colors based on a color chosen by the user.
The default on Mac OS X for color selection is to open a NSColorPanel containing multiple NSColorPickers. But, as the color selection process is the main interaction the user will have with the app, it'd be better to avoid the extra clicks and panel-popping in favor of a more straightforward way.
So, is there any way to add a NSColorPicker object to a window?
I know this is an older question, but check out NSColorWell. From the docs:
NSColorWell is an NSControl for selecting and displaying a single color value.
Interresting Question.
I strongly doubt it (but would love to be proven wrong). NSColorPickers are not NSControls (nor NSCells) so there's no clean wrapper to insert into a window.
Even if you were to instanciate an NSColorPanel and get a reference to its contentView and copy it (with all that defines the color picking controls) to your own window... there's no obvious way of obtaining the color value. NSColorPickers are plug-ins so you can't forsee the controls of a colorPicker.
The only other way I can see (and that's a stretch) would be to manually load the NSColorPickers plug-ins directly. I don't know how successfull this would be.
File a bug report and request the feature?

Resources