uilabel

How to calculate the Width and Height of NSString on UILabel

余生长醉 提交于 2019-12-08 01:58:59
问题 I am working on a project to make the NSString on UILabel Width and Height dynamically. I tried with: NSString *text = [messageInfo objectForKey:@"compiled"]; writerNameLabel.numberOfLines = 0; writerNameLabel.textAlignment = UITextAlignmentRight; writerNameLabel.backgroundColor = [UIColor clearColor]; CGSize constraint = CGSizeMake(296,9999); CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; NSLog(@

How to animate the textColor of a UILabel?

醉酒当歌 提交于 2019-12-07 22:19:08
问题 Could you please tell me how to animate the textColor of a UILabel ? For example I would like to change the color from WHITE to RED, then come back to WHITE with a fade-in effect and repeat that about 3 times. I need this animation because my app gets real time data from the internet and when a value is changed I need to animate this text value to tell the user that it has changed . Thank you so much. 回答1: The reason that textColor is not animatable is that UILabel uses a regular CALayer

Multi-colored UILabel text

风格不统一 提交于 2019-12-07 21:21:51
问题 Is is possible to create multi-colored text within a UILabel? I.e, if my text was: "The quick brown fox" have the q and b in blue with the rest of the text in black? I get the feeling I'd have to use a UIWebView and render the text in HTML to accomplish this. Thoughts? 回答1: You are correct that you need to use a UIWebView. Alternatively, you can draw the text yourself into a custom view, but that would probably be a lot more difficult to implement. If you are going to draw it yourself, you'll

Is it safe to add a “stolen” UILabel's layer to some other CALayer's sublayer?

你离开我真会死。 提交于 2019-12-07 19:41:26
问题 I read this and this but they don't seem to address the issue. And the answers to this seem to go off a tangent in NSCoding and friends, so ... Consider: - (NSAttributedString *) attributedStringForText: (NSString *) text { NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:text]; UIFont * bigF = [UIFont fontWithName:@"OpenSans-Extrabold" size:20.0f] ; UIFont * smaF = [UIFont fontWithName:@"OpenSans-Extrabold" size:12.0f] ; [attrStr addAttribute

TTTAttributedLabel “Read More >” tail truncation with several attributes possible?

旧时模样 提交于 2019-12-07 18:09:01
问题 TTTAttributedLabel support a custom truncation string via truncationTokenString as well as truncationTokenStringAttributes . However, I am wanting to go a bit further and set several string attributes on the truncation string, including different fonts and colours. This is what I am trying to achieve: The arrow at the end can be achieved using a font icon, so I was thinking of the following string: @"… Read More >" 'HORIZONTAL ELLIPSIS' (U+2026) + Read More + > character from a font .

Problem with custom label in UITableViewCell

本小妞迷上赌 提交于 2019-12-07 17:33:29
问题 I have UITableViewController. In cellForRowAtIndexPath method I added custom setup for label: UILabel *lblMainLabel = [[UILabel alloc]initWithFrame:CGRectMake(50, 9, 150, 25)]; lblMainLabel.text = c.Name; lblMainLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20]; lblMainLabel.backgroundColor = [UIColor clearColor]; lblMainLabel.textColor = [UIColor whiteColor]; [cell.contentView addSubview:lblMainLabel]; [lblMainLabel release]; But when I scroll UP or DOWN in table it always add

Slider view for iOS

别说谁变了你拦得住时间么 提交于 2019-12-07 16:56:12
问题 Can someone help me with this scenario? *There is a button, which when tapped, slides opens up a UIView, with the tapped button still to its left. *This button when tapped again, makes the UIView slide back. 回答1: What you describe is easy. Let's call the view that slides in from the right a drawer ("drawerView"). Set up the drawer view as a child view of your view controller's main view. Make that "drawer" view a container view. Put everything you want inside it. (Your text view, buttons, etc

Ios : How to align labels like whatsapp chat message label and time label?

不问归期 提交于 2019-12-07 16:30:56
问题 In whatsapp, if the message is very short, the text and time are in the same row. If the message is long, the time is in the bottom right corner - the text coming above it. How can i achieve this using Storyboard in Ios 回答1: Try using something like this to define last line width (Maybe you'll have to tweak text container a bit more for your case): public func lastLineMaxX(message: NSAttributedString, labelWidth: CGFloat) -> CGFloat { // Create instances of NSLayoutManager, NSTextContainer

Retain the resolution of the label after scaling in iphone

六眼飞鱼酱① 提交于 2019-12-07 16:30:50
问题 I am having a label in a view.After scaling the view, the label looks little blurred,the resolution is lost.How to retain the resolution after scaling. Here is my code for scaling secondView.transform = CGAffineTransformIdentity; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0]; secondView.transform = CGAffineTransformMakeScale(2 ,2); [UIView commitAnimations]; [self.view bringSubviewToFront:secondView]; 回答1: I set the ContentScaleFactor property of the label to

Custom UITableViewCell with Partially Bold Text

守給你的承諾、 提交于 2019-12-07 14:57:12
问题 Trying to implement a UITableView of names similar to the built-in Contacts iPhone app where the first name is in normal font and the last name is bold. A quick google suggests this isn't as easy as it sounds due to the iPhone SDKs lack of rich text support in UILabels. One of the solutions found recommended using a UIWebView to format the text allowing HTML bold tags to provide the required markup. Correct me if I'm wrong but this seems to be overkill and would have an affect on the