uilabel

Dynamically sizing text with kerning to occupy the full width of a UILabel

馋奶兔 提交于 2020-01-29 19:46:11
问题 I have a layout with a UILabel placed above a fixed width view, shown below as a grey rectangle. The text needs to match the width of the fixed grey view. I achieved this by setting the adjustsFontSizeToFitWidth property on the UILabel to YES , settings the font size to something really large, and setting the minimumScaleFactor to something suitable small. This worked fine until… I had to add kerning to said text. I added the kerning by applying @{NSKernAttributeName: @1.40} to an attributed

iOS UI 03 事件和手势

谁说我不能喝 提交于 2020-01-29 15:01:03
// // RootViewController.m // UI - 04 事件 , 手势 // // Created by dllo on 15/11/11. // Copyright (c) 2015 年 dllo. All rights reserved. // #import "RootViewController.h" @interface RootViewController () @property ( nonatomic , retain ) UILabel *label1; @end @implementation RootViewController - ( void )dealloc { [ _label1 release ]; [ super dealloc ]; } - ( void )viewDidLoad { [ super viewDidLoad ]; self . view . backgroundColor = [ UIColor whiteColor ]; // 轻拍手势 // UITapGestureRecognizer * tapGR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)]; // 为某一视图添加手势 //

How do I reuse a view inside UIPickerView in this case?

感情迁移 提交于 2020-01-25 10:14:38
问题 It seems that a lot of people just return a UILabel, but in my case I'm adding a label to a view. The view is never not nil. This is a different use of UIPickerView, because I'm rotating its components 90 degrees and having it scroll sideways instead of up and down. func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { if view == nil { let customWidth = 300 let customHeight = 300 let view = UIView(frame: CGRect(x:0, y

Is it now possible to have Multiline UILabel with adjustsFontSizeToFitWidth?

只谈情不闲聊 提交于 2020-01-25 08:53:10
问题 I struggled in the past to have UILabel adjustsFontSizeToFitWidth working on multiline labels. I soon have found also here on stackoverflow that adjustsFontSizeToFitWidth property "is effective only when the numberOfLines property is set to 1". I remember that this was written in the official documentation. But now I can't find it anymore I was testing my code on Xcode11 with the accessibility inspector to find out labels that needed to be embedded in scroll views. I found out a label that

Autoresize multiline UILabel in Swift

会有一股神秘感。 提交于 2020-01-24 22:08:44
问题 I have tried everything to auto-resize my UILabel in Swift. I can autoresize the text when it is one line but when it is two lines it no longer works. The text in the UILabel changes often happening about every 10 seconds. The code I have tried is: let direction = UILabel(frame: CGRect(x: 95, y: 10, width: screenWidth - 95, height:100)) direction.numberOfLines = 0 direction.adjustsFontSizeToFitWidth = true direction.lineBreakMode = .byWordWrapping direction.textAlignment = .center direction

Animate UILabel width with fixed center

好久不见. 提交于 2020-01-24 12:46:05
问题 How to animate a change in width while keeping the view centered? Currently when I do it, it doesn't grow from the center. self.textLabel = UILabel() self.textLabel.frame = CGRectMake(0, 0, Globals.voterTextLabel, Globals.voterTextLabel) self.textLabel.center = CGPointMake(self.view.frame.width/2, self.view.frame.height/2) self.textLabel.text = "VS" self.textLabel.layer.cornerRadius = Globals.voterTextLabel/2 self.textLabel.layer.masksToBounds = true self.textLabel.clipsToBounds = true self

How can I underline part of the text like iPhone SMS?

醉酒当歌 提交于 2020-01-24 10:13:23
问题 I use an UILabel to show my text, in a multi-line and UILineBreakModeWordWrap mode, and the maximum width is 200. For example, here is the text: I really really want to underline first word and second word, could you help me? And I want to underline "first word" and "second word". If the text is shown in a single-line mode, with sizeWithFont method of NSString, I can easily calculate the position of "first word" and then override - (void)drawTextInRect:(CGRect)rect to draw the line. But in

How to add padding to an UILabel? [duplicate]

我怕爱的太早我们不能终老 提交于 2020-01-24 02:40:47
问题 This question already has answers here : UILabel text margin [duplicate] (38 answers) Closed 6 years ago . The text inside an UILabel is smashed against the left and right borders. Is there an way of adding some inner padding to the UILabel, so that text won't touch the inner borders so closely? 回答1: Just adjust the position of the label (I'm not aware of any other method, although someone else might). If you have an issue with background colors (for instance), make the background a separate

iOS-UILabel实现文字缩进

烈酒焚心 提交于 2020-01-24 00:43:58
利用 NSMutableParagraphStyle 实现文字缩进 NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; // 对齐方式 style.alignment = NSTextAlignmentJustified; // 首行缩进 style.firstLineHeadIndent = 10.0f; // 头部缩进 style.headIndent = 10.0f; // 尾部缩进 style.tailIndent = -10.0f; NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:title attributes:@{ NSParagraphStyleAttributeName : style}]; UILabel *label = [[UILabel alloc] initWithFrame:someFrame]; label.numberOfLines = 0; label.attributedText = attrText; 来源: https://www.cnblogs.com/lancely/p/5782774.html

Create UIImage from 2 UIImages and label

一笑奈何 提交于 2020-01-23 09:03:16
问题 I got one big UIImage . Over this UIImage i got one more, witch is actually a mask. And one more - i got UILabel over this mask! Witch is text for the picture. I want to combine all this parts in one UIImage to save it to Camera Roll! How should I do it? UPD. How should i add UITextView ? i found: [[myTextView layer] renderInContext:UIGraphicsGetCurrentContext()]; But this method doesn't place myTextView on the right place. 回答1: create two UIImage objects and one UILabel objects then use