UILabel Font Size Does Not Change in XIB while Color Does - ios

This question seems simple, but this problem turned me crazy after days since none of the answers could solve my problem so far. I will be glad if someone can help me to figure it out.
So, I have a .xib file where I created a subview (called StaticDetailVerticalView) and I have also another .xib file for the whole page's view (called TripDetailView), and lastly, this TripDetailView is being used inside of a controller (called TripDetailViewController). My font problem occurs in StaticDetailVerticalView.
First, I was trying to set the fonts with an outlet from .xib with the methods [self.label setFont:[UIFont systemFontOfSize:20.0] and self.label.font = [self.label.font fontWithSize:20.0]. Then secondly, I tried setting from the TripDetailView by creating a IBInspectable fontSize inside StaticDetailVerticalView with direct setting from TripDetailView.xib file.
Also, when I try to change the color or the text by calling the methods exact same places with font changes, everything changes accordingly but the font size.
I hope there will be an answer to be accepted :) Joking aside, I really stuck in here.
Please ask me for further details, or any files that I can share for you if you need one. I am not adding the codes or screenshots since I believe this is not a problem by code based but something that I am missing about the outlets.
You can find the all three .xib files mentioned above here.
Thanks for all the helps and answers!

You can try to adjust the font size in your StaticDetailVerticalView.xib
Go to StaticDetailVerticalView.xib
Clic on the label you want to change the font's size
Clic on the button "Show the attributes inspector"
Then, you can change the font manually.

Related

Swift UIButton - How to remove underline?

I have problem when in iOS settings is enabled this setting "Button Shapes"
It causing this underline in application (first picture with enabled setting, second without)
Any idea how to programatically or in storyboard disable it?
I tried attributed text but I get same result :(
I'm newbie in Swift.
Thanks for help!
It's not a problem. You should not make any attempt to counter any accessibility changes set by the user. They are there for a reason.
This is an answer by user4291543 from this question Remove underline on UIButton in iOS 7
[yourBtnHere setBackgroundImage:[[UIImage alloc] init] forState:UIControlStateNormal];
I found this answer works with SWFrameButton
And for all the others saying "Don't Do This", SWFrameButton is a very good example of when you would want to do this. I also think the OP's situation is a perfectly valid scenario as well...
I totally agree with #maddy's comment:
It's not a problem. You should not make any attempt to counter any accessibility changes set by the user. They are there for a reason.
But I did stumble on a way to accomplish the task at hand...
In addition to a UIButton, you'll also need to make a .png file that contains nothing (meaning the entire contents have an opacity of 0%). Go ahead and load that into your xcode project's assets.
Now go ahead and set the Button's Background to that image you just provided. (In my case, I called it clear) This will remove the underline from the button's text. However, now you can't see the boundaries of the button. This can be solved by changing the Background of the button's View. Go ahead and select any color for the View's Background property and now the background of the View visibly defines the button's boundaries. You're able to see this because your clear.png has an opacity of 0%.
see the Attributes inspector for UIButton here.
Rather than trying to defeat the underline by going to make a label perform some action via UITapGestureRecognizer, this allows you to still use a UIButton. Keeping inline with accessibility features to mark buttons for people that want to do that.
You could create a custom button class with a label (with clear color). If you set the text of this label instead it shouldn`t get an underline.
Are you sure you want to do that?
Apple added an accessibility feature to mark buttons for people that want to do that. Apple will probably reject your app because it defeats a system function meant to help the disabled.
I found the solution. All you have to do is set a picture as the background of the button. just pick a picture with the same color as the button you created.

Swift iOS localization - not all strings in main.strings (xcode 6.3)

I try to localize my iOS app. Unfortunately I run into trouble with the localization. My problem is by adding the additional language, not all strings are listed in the main.strings file for the additional language. I have an scroll view and an label in my ViewController. The scroll view itself also has many label. Wenn I go into the main.string file, I miss the separat label as well as the first label in the scroll view.
Because the controller is the second view controller working as a description view, I've not added IBOutlets to the label. Just use them as text.
Does anyone know how to add these two label to the main.string file or maybe just give me a hint what I can check to see what's maybe wrong?
Thanks in advance
Ok, after two additional days I've found the reason why it was not working. At all I hope my question was not to silly and all member just thought RTFM.
I've solved my following problems:
1) How can I add additional Label-Text to the Localization file "main.strings" and
2) By adding an Language not all text are entered by Xcode to the main.stings file.
1)
In the document block from the identity inspector is a filed called Object ID. This is the Xcode generated reference to the Label (Text). Adding this to the specific language main.strings file with, close the line with an ";" and it works.
2)
Well, as far as I could investigate, localization just works with plain text (Attributes Inspector - Block Label). It does not work with attributed text. Maybe I did something wrong, but changing to "Plain" and problem was solved.
Thanks for all who spend some time to read my question.

Custom fonts using xcode through attribute inspector

I am using Xcode 6.1 interface builder.
I want to have a universal UILabel font throughout the app in which I can easily change.
For example I want all my UILabel to use font 'A.otf' and later I would like to update all my UILabel to be something else like 'B.otf'
My first attempt is to subclass UILabel(lets call it MyCustomUILabel) and set its font attribute to whatever font I want. With this solution, I just have to make sure I set the UILabel to MyCustomUILabel in the identity inspector. And if I do need to change the font for all MyCustomUILabel, I will need to change it within the MyCustomUILabel class.
My second attempt is to use Xcode's built in custom font helper(attribute inspector -> font icon -> custom -> select my font). I was thinking if Xcode already provided a way to custom a font of my UILabel, then why create a custom class?
Using the Xcode built in custom way, I have a UILabel using 'GoodPro-Book.otf' as the custom font right now. I wanted to update this UILabel's font to 'Sanitarium.otf' and I was hoping that all I have to do is just rename my 'Sanitarium.otf' to 'GoodPro-Book.otf' and replace the one inside Xcode with this new one.
Of course it didn't work out.
So, I would like to ask, is this possible? in Xcode? Am I missing anything?
thanks, any suggestions and opinions are appreciated.
I think the font family and style are contained within the font file, so renaming the file doesn't have an effect. Unfortunately, I've never found a way to change Xcode's default font for a project (that would just make things too easy).
I think you're right in that the best way to change them all at once is to subclass UILabel and make sure you always use your subclass. Otherwise you have to change them all by hand.

Is it possible to customize a text field , in iOS?

i am in need to use a text field in my application but the ones provided by XCode are only 1 line long and you can only change the width but not the hight.
I was wondering if its possible to make it look more lines long?
Is it only possible with customization and if yes any good tutorials?
Thank you!
First off, you can actually change the height of a UITextField. Just change the border style in the Attributes Inspector to anything except the default "rounded corners". You can then resize it right in Interface Builder. If you really wanted to, you could even change it back in your viewDidLoad method like this:
self.myTextField.borderStyle = UITextBorderStyleRoundedRect;
However, to have multiple lines, you have to use a UITextView. It's by default multi-line, but see the Apple documentation for more information.
You can use a UITextView. The document about it here. If you need something else, please post an image of what you want to achieve.

How to write multiple lines in a label

I have a XIB file of type View XIB. In it I have a View controller, and in the View controller I have a label.
I have long text that I want to break, but it doesn't - it gets truncated.
I tried this solution - I did it in the attribute window - but it doesn't help.
You could use a TextView and disable the Editable and User Interaction Enabled options in IB.
use this
myLabel.lineBreakMode = UILineBreakModeWordWrap;
if you are worried about backwards compatibility use this because the comand i mentioned before was introduced in iOS 6.0
myLabel.numberOfLines = 0;
I have been running into a similar problem. I started out with a label, but wanted multi-lines and a UITextView worked great for this, at first. Because I am using a third party library (MBProgressHUD) to handle stuff like progress messages and what not, I had thread problems when trying to update a UITextView and show the progress message at the same time.
So I went back to UILabel which actually didn't have thread problems. I found a property to allow a specific number of lines of my choosing, and had to create the label big enough to display those lines. The downfall to this approach is that I don't get the context menus like Copy, Paste, etc. but more importantly I'm not running into thread problems. I can always embed this into a UIScrollView in the future if I so choose.
You could check out my category for UILabel on GitHub. https://gist.github.com/1005520
This lets you resize the height of the label to accommodate the content.
From the Attiribute inspector, choose LineBreaks->Word Wrap option when you have selected the lablel. Also increase the number of lines Label->Lines.
Try Following steps to solve issue :
Drag out a UITextView.
Double-click it to edit text, place cursor where you want the
paragraph break.
Option-Enter a couple of times to create a blank line & paragraph.

Resources