Set the default font style, color, and size for an xcode project - ios

The app I'm working on has a particular color scheme, so I was wondering if it is possible to set a "default" background color, text color, and font size so that every time I create a new view, or label in Interface Builder I don't have to change all of these parameters.

As of iOS 5, there is the UIAppearance protocol that all of the standard UI elements implement. Using the "Appearance proxy" you can set the appearance for ALL objects of that type in a given application. More information can be found in the incredibly helpful and informative WWDC '12 session on "Advanced Appearance Customization on iOS"

How about just creating a DanFViewController (subclassed from UIViewController) that already has the specific background color, text color, font size, etc. you need and then derive all your app's custom views from that?
That's what I do in my own apps where clients are expecting a certain look & feel for all the views.

Related

Disable Automatic adjusting font for UILabel,UIText,etc. in iOS/Swift?

Go to "Settings"-> "General"-> "Accessibility"-> "Larger Text" to change the font size.
Open my app, now all the UILabels and UIButtons do change accordingly. I want to disable it and want to keep as it is regardless of the large font or small font on the setting. I have made everything programmatically. How can I disable this?
myLabel.adjustsFontForContentSizeCategory = false
Although this depends on the font that you're using. See more info here: https://developer.apple.com/documentation/uikit/uicontentsizecategoryadjusting/1771731-adjustsfontforcontentsizecategor?language=objc.
Specifically, this part:
For this property to take effect, the element’s font must be vended
one of the following ways:
It must be vended using the preferredFontForTextStyle: or
preferredFontForTextStyle:compatibleWithTraitCollection: method with a
valid text style.
It must be vended using one of the scaling methods from UIFontMetrics.

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

In iOS, is there any standard mechanism for color pickers?

I'm at a loss trying to find anything relevant to this question. Basically, I'm looking to write an app that's kind of like a color picker / swatch library (but with a certain purpose in mind) and I'd like to be able to use it in virtually any app that deals with color selection. Is there any built in, or perhaps novel way, I could either modify some config variable, or send some kind of signal that updates the current color? Or I guess the real question would be, is there any concept of a global color in iOS?
Maybe you are referring to tintColor?
From Apple guidelines:
Using Tint Color
In iOS 7, tint color is a property of UIView. iOS 7 apps often use a
tint to define a key color that indicates interactivity and selection
state for UI elements throughout the app.
When you specify a tint for a view, the tint is automatically
propagated to all subviews in the view’s hierarchy. Because UIWindow
inherits from UIView, you can specify a tint color for the entire app
by setting the window’s tint property using code like this:
window.tintColor = [UIColor purpleColor];
From Apple docs:
The first nondefault tint color value in the view’s hierarchy,
ascending from and starting with the view itself.
I hope that helps.

iOS Format Background

I am creating a simple quote app as a learning experience and need to format it to look better.
I am trying to make the background have a "white square" where the text is and make the text black. Just like the Twitter app has when you click on a tweet.
What is the best way to do this and what should I start with?
I know it is very simple, I'm only 15 and am trying to learn iOS. As you can see I have a server and have the app up and running, just want to format before I call it complete. Thanks! :)
-Henry
This will depend on how you created the label that displays your text, but you can do this very easily:
If you created your UI in a Storyboard / XIB file in XCode: assuming you dragged out a UILabel or UITextView, you can use the Attributes Inspector to set the text color and the background color (in the View section) of the element holding the text.
If you created the label (or text view) in code, you can set the textColor property and the backgroundColor properties programmatically.

Changing the font of every UILabel in a large app

Here's an interesting problem for you:
We are in the process of re-skinning our entire app, which consists of over 100,000 lines of code and almost 100 XIB files. The new design requires (almost) every label in the app to use a new custom font, whereas the old app uses the default font of Helvetica Neue.
What is the most efficient way of changing as many of the UILabels as possible? We don't want to have to manually change thousands of labels both in code and in XIBs (which is especially difficult because we are using a non-system font).
We've discussed swizzling UILabel's creation methods to default to using the new custom font, which would still allow for the few labels that would remain in Helvetica Neue to be customized after creation.
Thoughts?
Take a look at NUI https://github.com/tombenner/nui.
You can customize a lot controls with it using a CSS-like stylesheet and implement it via subclasses or categories.
You should probably subclass UILabel and override either an initmethod of your choice, or awakeFromNib, and set the custom font there. Then you can go through the xib, either manually, or open it up in a text-editor and add a line like
<string key="X.CustomClassName">YourCustomLabelClass</string>
To set the specified label to your custom label class.
Swizzling is a good option . If you want to do it other way and have problems with custom fonts, I usually make a trivial subclass of UILabel that changes it's font in awakeFromNib for each custom font so I can lay them out in the interface builder.
But... This comes to my mind:
[[UILabel appearance] setFont:xxx];
I am not sure how you would deal with keeping the size, though. Perhaps swizzle is the best choice

Resources