Lets say I want to make only the text "Software" bold. Is there a way to achieve this without a custom alertview?
self.subHeadingLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
Check out dynamic text in ios7 . it has six different font styles. There is a good article here
Related
The Apple documentation says that for iOS an app can use text styles and dynamic font type so text size automatically adjusts to the users reading preferences.
I have a text style Body and set Dynamic Type to true so that it automatically adjust the text size. This works good.
This text I would also like to make appear bold. I haven't found a way yet how to achieve this either by code or in the Interface Builder.
Is there a way to achieve a "bold dynamic font type"?
Ok, it seems the documentation provides a hint. For using custom fonts, I consider a bold font as a custom font now, one can use the UIFontMetrics class.
If I pass a "bold custom font" to the scaledFontForFont method of UIFontMetrics class I get the desired result with the dynamic font type UIFontTextStyleBody.
UIFont* boldSystemFont = [UIFont boldSystemFontOfSize:17];
myLabel.font = [[UIFontMetrics metricsForTextStyle:UIFontTextStyleBody] scaledFontForFont:boldSystemFont];
So far I only see this way using code. No idea if this could somehow be setup in the Interface Builder as well.
I am trying to make a UITextView to have two links in it as text, but with different colors. I am not sure if it's possible at all.
I have set the UITextView to detect links, not to be editable, but only selectable.
What I did so far is the following:
NSMutableAttributedString *termsAndConditionsTitle = [[NSMutableAttributedString alloc] initWithString:#"I have read the " attributes:#{NSLinkAttributeName: #"https://apple.com", NSForegroundColorAttributeName: [UIColor greenColor]}];
NSMutableAttributedString *someString2 = [[NSMutableAttributedString alloc] initWithString:#"terms and conditions" attributes:#{NSLinkAttributeName: #"https://microsoft.com", NSForegroundColorAttributeName: [UIColor redColor]}];
[termsAndConditionsTitle appendAttributedString:someString2];
[self.termsAndConditionsView setAttributedText:termsAndConditionsTitle];
But in the end the links just have the tint color of the UITextView. Is it possible to make the two link have different colors? Thanks in advance!
P.S. I don't want to use libraries/frameworks if possible.
Yes it is possible, the problem is that the TextView has some predefined attributes for the links.
To fix it you just have to remove them in this way:
yourTextView.linkTextAttributes = [:]
With this line of code if the textview detects a link it won't apply any special attribute to it. So it will work as usual but without changing the color of the links. If you want to change the colors, you'll have to do it manually when you are adding the attributes.
You'll need to assign your text view's linkTextAttributes - basically you just tell your text view to identify links and stylize them however you specify:
Objective-C
textView.linkTextAttributes = #{
NSForegroundColorAttributeName:[UIColor someColor],
NSUnderlineStyleAttributeName:#(NSUnderlineStyleSingle)
};
You should also be able to assign the tintColor (since UITextView's inherit the same behavior as UIView's and will use this color for links). But if that isn't working for whatever reason in your case, assigning the link attributes will be the solution.
If your intention was to have two different colors for each link, then you will have to manually assign the attributes of each link based on the range at which each link occurs in your string.
I want to put 2 lines in the title of UIAlertView with first line in bold and bigger font and second line with regular and smaller font.
Is there a direct way of doing it or do I need to extend the UIAlertView to write my own custom alert view. Any pointers.
UIAlertview has a title property and a body property. The body property is a non bold and I think smaller font than the title property. You could use the body as your smaller title property unless you need two titles and a body, in that case, you will have to roll your own.
As far as I konw,before ios 7,you can write two UILabel,one text bold and one not.
Then add these subviews to UIAlertview.
Now,I think the only way is to define your own UIAlertView.It is easy.
I want to insert a URL hyperlink into a UITextField that has different display text.
This is super easy in html:
Go To Google
How can I do this in iOS?
You can change the text style inside your UITextField via an attributed string sent to the text field's "attributedText" property.
However, what I suspect you really want to do is have a link that's clickable. I would recommend using a UIButton with a custom type (i.e. no border) and you can set the color and the underline style.
But like Evan said, if you have multiple lines of text, it may be smarter to use a UITextField where you set "editable" to NO and turn on the LINK traits (both of these you can do from the object inspector in Xcode).
Alright, so here's what I did to get what I wanted. I used UIWebView, and simply linked it to an html page in the project that has the text, and hyperlink at the bottom with different text displayed.
Answer is here :
If you want it as clickable Hyperlink,
NSString *string = #"Go To Google";
You need to add "BACKWARD SLASH" before ". That's it.
I looked at a few examples here on OS and also followed this one but what I wanted to know is how I can set a custom font for only one specific label.
This line is supposed to change the font:
[UIFont fontWithName:#"Cloister Black" size:64.0]
But I don't want everything to be affected. Any ideas how I do this?
Setting the font on a label is as easy as modifying that label's "font" property (and I've linked Apple's documentation for you).
E.G.:
labelIWantToModify.font = [UIFont fontWithName:#"Cloister Black" size:64.0];
And I'm hoping you're referring to that one specific label, and not a piece or part of the string that appears within the label, which is a separate (attributed string) thing.