I need one help i don't know how to implement bullet in UILabel text. I search lots of links but couldn't find the solution. Please help me. Waiting for a solution.
Thanks in advance.
Use the Unicode code point for the bullet character in your string?
Try This:
myLabel.text = #"\u2022 This is a list item!";
You should take a look at AliSoftware's OHAttributedLabel. It is a subclass of UILabel that draws an NSAttributedString
try this:
#import "OHAttributedLabel.h"
#import "NSAttributedString+Attributes.h"
OHAttributedLabel *myLabel=[[OHAttributedLabel alloc]init];
[myLabel setFrame:CGRectMake(0, 0, 70, 20)];
NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:#"\u2022 list item!!!"];
[attrStr setTextColor:[UIColor redColor]];
[attrStr setTextColor:[UIColor blackColor] range:NSMakeRange(0,1)];
myLabel.attributedText = attrStr;
[self.view addSubview:myLabel];
if you want to add just bullet than use this:
myLabel.text = #"\u2022 list item!!!!!!!!!";
List of more unicode
hi #Anamika Try this also
myLabel.text = #"\u25A0 This is a list item!";
and for more shapes you can chage the value from here :
http://www.alanwood.net/unicode/geometric_shapes.html
If formatting your text with bullets is a concern, I found this Stack Overflow post helpful. They show you how to create and align paragraphs containing bullets using storyboard.
Cmd+K on a mac will insert a bullet character.
Related
I'd like to set an action to a "part" of UILabel not the all of UIlabel, like the "term of service" of attached picture. I am using storyboard. Now, I'm thinking to cover the UIButton over the part of UILabel. However, it is troublesome to adjust the part of label with the button at any layout(iPhone 5, 6 and 6 plus) by autolayout. If you know better way, please tell me. Thank you for your kindness.
I'd recommend using a UITextView with an NSAttributedString. Get the range of the text you are looking for, and then add the button as a subview to the view.
NSRange termsOfServiceRange = [self.termsOfUseTextView.text rangeOfString:#"Terms of Service"];
self.termsOfUseTextView.selectedRange = termsOfServiceRange;
UITextRange *termsOfServiceTextRange = [self.termsOfUseTextView selectedTextRange];
CGRect termsOfServiceFrame = [self.termsOfUseTextView firstRectForRange:termsOfServiceTextRange];
CGRect convertedFrame = [self.view convertRect:termsOfServiceFrame fromView:self.termsOfUseTextView];
UIButton *termsOfServiceButton = [[UIButton alloc]initWithFrame:convertedFrame];
[termsOfServiceButton setBackgroundColor:[UIColor clearColor]];
[termsOfServiceButton addTarget:self action:#selector(termsOfServiceButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:termsOfServiceButton];
[self.view bringSubviewToFront:termsOfServiceButton];
I've solved by using TTTAttributedLabel!
https://github.com/TTTAttributedLabel/TTTAttributedLabel
I asked a developer (TwoLivesLeft, the creators of Codea) how they did syntax highlighting in their app. He replied :
#TD2 the Codea editor is implemented using a UITextView. The
highlighting is done by overlaying subviews in the appropriate
positions — usually UILabels. They are dequeued from a re-use pool,
similar to the way UITableViewCells work. During scrolling, the lines
requiring re-highlighting pull markers out of the pool and lines that
have moved off screen dump their markers back into the pool.
Can anyone explain how I would get the x and y of a certain word?
UITextView conforms to UITextInput, of which a detailed description can be found here.
Take a look at the required methods "textRangeFromPosition:toPosition:", "positionFromPosition:offset:", "positionFromPosition:inDirection:offset:", and some of the other geometric-based methods in the UITextInput Protocol. Those might provide the functionality you are looking for.
I have not actually tried to make sure these work the way you want them too, but that looks like its about what you need.
Let me know if you need any more help!
UPDATE:
Here is some sample code of how to do this. I ended up getting the "firstRectForRange:" method to work. This code basically takes the last three letters of the UITextView "textStuff" and highlights it green.
UITextView *textStuff = [[UITextView alloc] init];
textStuff.frame = CGRectMake(2.0, 200.0, 200.0, 40.0);
textStuff.text = #"how are you today?";
textStuff.textColor = [UIColor blackColor];
UITextPosition *Pos2 = [textStuff positionFromPosition: textStuff.endOfDocument offset: nil];
UITextPosition *Pos1 = [textStuff positionFromPosition: textStuff.endOfDocument offset: -3];
UITextRange *range = [textStuff textRangeFromPosition:Pos1 toPosition:Pos2];
CGRect result1 = [textStuff firstRectForRange:(UITextRange *)range ];
NSLog(#"%f, %f", result1.origin.x, result1.origin.y);
UIView *view1 = [[UIView alloc] initWithFrame:result1];
view1.backgroundColor = [UIColor colorWithRed:0.2f green:0.5f blue:0.2f alpha:0.4f];
[textStuff addSubview:view1];
Result of running this code:
#bddicken's https://stackoverflow.com/a/11487125/3549781 works like a charm. But the problem is, it doesn't work on iOS 7+ if the text contains a newline "\n". After a lot of searching I found a solution for that.
You have to ensure the layout of textView before calling firstRectForRange: by
[textView.layoutManager ensureLayoutForTextContainer:textView.textContainer];
Courtesy : UITextView firstRectForRange not working when there's new line characters in the mix
P.S : At first I added this as a comment to #bddicken's answer. As most people don't read comments I added this as an answer.
I'm using an underscore character below each form field and related label in my view to logically seperate them. I've added the underscore in a UILabel but I'm looking for a way to repeat the _ without having to manually type it many times in the text property of the label in IB. Any idea on how to do this ?
I tried checking/unchecking "adjust to fit" but it's not working.
Thx for helping
Stephane
This is vague question, but if you want a line, I think you should rather insert generic UIView with backgroundColor that imitates the line.
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(linex, liney, thickness, length)];
line.backgroundColor = [UIColor blackColor];
[view addSubview:line];
[line release];
No matter how you'd look at this, this is much better solution than inserting undersocres.
I want to make my label as shown in the image
I know I can get this effect by putting image view on it.
but is there any other method to do ?
How can I put line on label ?
Try this,
UILabel *blabel = [[UILabel alloc] initWithFrame:CGRectMake(XX, 6, 271, 26)];
blabel.text = #"Hellooooooo";
blabel.textAlignment = UITextAlignmentCenter;
blabel.backgroundColor = [UIColor clearColor];
blabel.textColor = [UIColor blackColor];
blabel.font = [UIFont systemFontOfSize:14];
[scrollDemo addSubview:blabel];
//underline code
CGSize expectedLabelSize = [#"Hellooooooo" sizeWithFont:blabel.font constrainedToSize:blabel.frame.size lineBreakMode:UILineBreakModeWordWrap];
UIView *viewUnderline=[[UIView alloc] init];
viewUnderline.frame=CGRectMake((blabel.frame.size.width - expectedLabelSize.width)/2, expectedLabelSize.height + (blabel.frame.size.height - expectedLabelSize.height)/2, expectedLabelSize.width, 1);
viewUnderline.backgroundColor=[UIColor blackColor];
[scrollDemo addSubview:viewUnderline];
[viewUnderline release];
The line above will appear below the text. You just need to change Y for UIView and it'll do wonders :)
put another label with "_" over it
transparent background.
you can create UIView with line's height and width and give background color to it. Put UIView over your UILabel .
For one of my projects I've created an UILabel subclass, which supports multiline text, underline, strikeout, underline/strikeout line offset, different text alignment and different font sizes.
Please see provided link for more info and usage example.
https://github.com/GuntisTreulands/UnderLineLabel
Place a UIImageView with line image on your label so when you run application it will fit.
In my application I want to draw UILabel dynamically depends upon string in DrawRect method...How can draw this?
You want to change the UILabel frame according to your textSize?? If so, refer this post.
Try the code below..
It worked for me in the case of button title. :)
CGRect oldLblRect = lbl1.frame;
lbl1.titleLabel.font = [UIFont systemFontOfSize:15];
[lbl1 sizeToFit];
lbl1.frame = CGRectMake(lbl1.frame.origin.x - ((lbl1.frame.size.width - oldLblRect.size.width)/2), lbl1.frame.origin.y - ((lbl1.frame.size.height - oldLblRect.size.height)/2), lbl1.frame.size.width, lbl1.frame.size.height);
Hope it helps. :)