Alternative to setTintColor for pre-iOS5 UIBarButtonItems? - ios

are there any alternatives to using the accessor setTintColor for UIBarButtonItems in order to add ios4 compatibility?
is it possible to modify the setter to include a conditional statement for systemVersion (without subclassing UIBarButtonItem)?

There are three approaches to do this. First, is to draw a button with CoreGraphic. Second, use a custom image. The third approach is probably the easiest and allows you to use a tintColor property for dynamic changes if wanted.
The idea is to create a UISegmentedControl and stylize it to look like a button and use that tintColor property to change the color of the "button".
You can find specific details at this webpage http://charles.lescampeurs.org/2011/02/10/tint-color-uibutton-and-uibarbuttonitem .

Related

how to add checkmark in UISwitch control?

Hello everyone i am trying to add a checkmark on UISwitch control. I do not know where to start. Any help appreciated. Result should be like the image below. Actually i have already an implementation without the checkmark but i need to add the checkmark somehow.
The short answer is that you can't do it with UISwitch. Before iOS 7 you used to be able to set on/off images, but those properties are now deprecated. If yo don't like the default styling, you have a few options:
You could add a floating image on top of the UISwitch like #DonMag suggested. This is probably the easiest way to go, but might not end up with the exact visual treatment you want.
You can use use a UISegmentedControl or a UIButton. Both of those classes have ways to set custom images for different states. UIButton is likely simpler to customize than UISegmentedControl.
You can build your own UIControl or use an open source custom control (i.e. from Cocoapods, or other source). Going open source will be easier than building your own.

how to do styling/themeing in xamarin.ios app

Let's say I want to use a different font, different font sizes, and a different color scheme for my app, and let's say I want to use Interface Builder.
I want to be able to style all these in one place, instead of say going to each label on Interface Builder and changing its font, color, etc.
What is the most common way to achieve this?
I know you can set these things up in code, but then I can't see the changes in Interface Builder?
Having to change these all one by one is a maintenance nightmare, and I can't seem to find any easy way to create custom styles directly in Interface Builder.
The only way I can think of is subclassing each of these views, such as label, button, etc., creating XIBs for each, and making them #IBDesignable.
Is this the way to go? It feels like it's just an unnecessary amount of work, for something simple.
If you want to change simple properties of UIKit controls, you can use UIAppearance.
With UIAppearance, You can change appearance like, TextColor, Backgorund color, Tintcolor etc for almost all UIKit Controls.
for ex:
Change UIbutton's title Color appearance:
UIButton.Appearance.SetTitleColor (UIColor.Brown, UIControlState.Normal);
Change UILable's Background Color appearance
UILabel.Appearance.BackgroundColor = UIColor.Blue;
Well, If you want to customise it to next level- Only way is by long process like Subclassing controls as you explained in your question

How to implement tintcolor behaviour for UIButtonTypeCustom

I'm using a custom button type since I need the touch areas to be non-rectangular so am using a class called OBShapedButton which I shamelessly found online. However, I also want to color these buttons to match the player's color.
When talking about UIButton and tintcolor, Apple's docs say
This property has no default effect for buttons with type
UIButtonTypeCustom. For custom buttons, you must implement any
behavior related to tintColor yourself.
So how would I go about implementing this behaviour myself?
you could create an array of colors using UIColor within your class then access them individually have you tried it that way?
ok as an example something like this
UIBarButtonItem.appearance().tintColor = UIColor.yellowColor()
ideally can you post your class code aswell

iOS add view to Button in IB

I am trying to add a view on a UIButton inside IB. The only problem it doesn't allow me to put in inside the button only on top?
Is this not possible through IB or am I doing it wrong?
It's not possible in Interface Builder. You have to add it in code.
You should not do this:
Do Not Customize Controls by Embedding Subviews
Although it is technically possible to add subviews to the standard system controls—objects that inherit from UIControl—you should never customize them in this way. Controls that support customizations do so through explicit and well-documented interfaces in the control class itself. For example, the UIButton class contains methods for setting the title and background images for the button. Using the defined customization points means that your code will always work correctly. Circumventing these methods, by embedding a custom image view or label inside the button, might cause your application to behave incorrectly now or at some point in the future if the button’s implementation changes.
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW26
If you need to add a UIView on your UIButton you can achieve it in 2 different ways
The easy way is to follow Cyrille answer: you can do it programmatically because IB doesn't allow you to modify a UIBUtton adding a view on it
The hard way is to create your custom button (let me call it "MYCustomButton"), that extends a UIButton, and use it in your application. With this way when you need to modify the buttons in your interface, you can achieve it modifying the XIB of the "MYCustomButton".

Customizing UITabbar idea ?

I read many posts on customizing color of selected tabbar item which is actually blue by default.
My idea was to put an UIImageView on each of my button.
Once the user select one button, I would then display the image (which is the same icon but with another colour as a gradient).
What do you think about that ?
Thanks in advance
You could always use this http://idevrecipes.com/2011/01/04/how-does-the-twitter-iphone-app-implement-a-custom-tab-bar/ and change it to include text and modify the colour.
Thankfully, iOS 5 introduced an appearance proxy allowing customisation of most basic UI elements, including the trusty UITabBar. The proxy is used to change ALL instances of a class throughout an application. However, with this came some basic properties available for specific instances.
See the selectedImageTintColor property of UITabBar for your needs.
Other appearance additions for this class are tintColor, backgroundImage and selectionIndicatorImage.

Resources