For example, I would like to display something like this:
It is my
boldtext label.
But It is my
's length cannot be expected, because, it may become
Oh! It is my
bold text label.
So, I can't use 3 labels to do so. Any recommends? Thanks.
For example, I would like to display something like this:
It is my
boldtext label.
But It is my
's length cannot be expected, because, it may become
Oh! It is my
bold text label.
So, I can't use 3 labels to do so. Any recommends? Thanks.
UILabel cannot do this out of the box.
I recommend using OHAttributedLabel, which is available on github.
You can still use 3 labels :)
Assuming the It is my
label is label1
, write a wrapper function that you always call to change label1
's text; this function should also recalculate label1
's size and reposition label2
and label3
.
-(void) setLabel1Text(NSString* newText)
{
label1.text = newText;
int label1TextLength = [label1.text sizeWithFont:label1.font];
label2.x = label1.x + label1TextLength;
label3.x = label2.x + label2.width;
}
And voila :)
Using a 'UILabel', this is not strictly possible. You can use bold fonts, however, if you want all text to be bold. Reference thithis page for a list of fonts. For example, instead of Helvetica, you can use Helvetica-Bold. With plain UILabel
s, however, formatting is all or nothing; all the text has to be bold, or none of it is bold. To display rich text with some parts bold, other parts not, however, check out NSMutableAttributedString
.
Good luck!