uilabel

Swift : align UILabel text in the top rather in the middle

邮差的信 提交于 2019-12-18 11:33:30
问题 I want the UILabel to start from the top even if the text is short it seems that NSTextAlignment doesn't work cell.textContent.text = comments[indexPath.row] cell.textContent.textAlignment = func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { //post's section == 0 if indexPath.section == 0 { let cell = tableView.dequeueReusableCellWithIdentifier("postCID", forIndexPath: indexPath) as! postCell cell.usernameLabel.text = "Steve Paul Jobs"

How to show Emoji in UILabel iOS

纵然是瞬间 提交于 2019-12-18 11:26:10
问题 I have to show the textview text smily in UILabel. In the UILabel - lbl.text = @"Happy to help you \U0001F431; its showing properly. In UITextView - I tried to convert UITextView text in string and then log is - %F0%9F%99%88%F0%9F%99%89%F0%9F%99%8A How to encode which i can show in UILabel , anybody please suggest me. 回答1: NSString *str = @"Happy to help you \U0001F431"; NSData *data = [str dataUsingEncoding:NSNonLossyASCIIStringEncoding]; NSString *valueUnicode = [[NSString alloc]

How to stretch Image to fill the Label Width set in Background in UILabel?

隐身守侯 提交于 2019-12-18 10:57:23
问题 I have simple View based application. I had taken only UILabel on it. Following is my code in viewDidLoad: lblBack.textColor = [UIColor blueColor]; UIImage *img = [UIImage imageNamed:@"cn3.png"]; lblBack.backgroundColor = [UIColor colorWithPatternImage:img]; lblBack.text = @"Hello World!!!..."; // UIImageView *imgView = [[UIImageView alloc] initWithImage:img]; // // CGRect rect = CGRectMake(0, 0, lblBack.frame.size.width, lblBack.frame.size.height); // [imgView setFrame:rect]; // NSLog(@"Rect

Adjust letter spacing in iOS 7

你说的曾经没有我的故事 提交于 2019-12-18 10:33:08
问题 In iOS 7, when navigating back using the new swipe-from-edge-of-screen gesture, the title of the Back button ("Artists") fades from being pink (in the example below) and having regular font weight to being black and having bold font weight. It seems to me that the animation uses two different labels in order to achieve this effect; one fading out as the other fades in. However, Apple has somehow adjusted the font so that the regular label perfectly overlays the bold one, thus creating the

How to render stretched text in iOS?

风流意气都作罢 提交于 2019-12-18 10:31:31
问题 Given a rectangular area, I want to render some text using a specific font and have the rendered text fill out the rectangle . As in the image below: This is not the same as just changing font size Rendering it as a bitmap and then scale it is not an option (it looks horrible) Vector graphics is the way to do it Solution I came up with the following which seems to work for my purposes. The code draws a single line of text scaling to fill the bounds. Subclass UIView and replace drawRect as

How to make URL/Phone-clickable UILabel?

孤街醉人 提交于 2019-12-18 10:24:11
问题 I want to create a clickable label on my app leading me to a Safari webpage. I also want the user to be able to phone the numbers only by clicking on them ? Thanks for your advices 回答1: You can use a UITextView and select Detection for Links, Phone Numbers and other things in the inspector. 回答2: Use UITextView instead of UILabel and it has a property to convert your text to hyperlink. Objective-C: yourTextView.editable = NO; yourTextView.dataDetectorTypes = UIDataDetectorTypeAll; Swift:

UILabel font size?

 ̄綄美尐妖づ 提交于 2019-12-18 10:13:21
问题 I can't seem to modify the font size of a UILabel with the following code: itemTitle.font = [UIFont systemFontOfSize:25]; As i increase the number 25 to something greater, it seems to only add a top margin to the label, which consequently pushes the text down so much, so that the text gets cut off at the bottom or completely overflows. i have another UILabel elsewhere with systemFontOfSize 25, and it's much smaller than the itemTitle text. What's going on? Isn't 25 supposed to be an absolute

Vertically align text within a UILabel (Note : Using AutoLayout)

跟風遠走 提交于 2019-12-18 10:06:18
问题 I am Copying the same Question asked Before Question. I have tried the solutions given and was not able to solve it since sizetofit was not effective when I use Autolayout. The expected display is like below. 回答1: Edit In my original answer I was using the paragraph style of the label. Turns out that for multi-line labels this actually prevents the label from being multi-line. As a result I removed it from the calculation. See more about this in Github For those of you more comfortable with

UILabel - Wordwrap text

﹥>﹥吖頭↗ 提交于 2019-12-18 09:56:06
问题 Is there any way to have a label wordwrap text as needed? I have the line breaks set to word wrap and the label is tall enough for two lines, but it appears that it will only wrap on line breaks. Do I have to add line breaks to make it wrap properly? I just want it to wrap if it can't fit it in horizontally. 回答1: If you set numberOfLines to 0 (and the label to word wrap), the label will automatically wrap and use as many of lines as needed. If you're editing a UILabel in IB, you can enter

How to set label height for auto adjust in Read More/Less with Swift 3?

99封情书 提交于 2019-12-18 09:44:11
问题 I would like to create the paragraph with Read More/Read Less at the end. Here are my codes; func getLabelHeight(text: String, width: CGFloat, font: UIFont) -> CGFloat { let lbl = UILabel(frame: .zero) lbl.frame.size.width = width lbl.font = font lbl.numberOfLines = 0 lbl.text = text lbl.sizeToFit() lbl.adjustsFontSizeToFitWidth = true return lbl.frame.size.height } @IBAction func btnReadMore(_ sender: Any) { if isLabelAtMaxHeight { btnReadmore.setTitle(NSLocalizedString("Read more", comment: