uilabel

Draggable label - ios

爷,独闯天下 提交于 2020-01-10 05:30:14
问题 I have a requirement to move a label around only when the user touches on it and drags. I cant find out whether the user touched that label or not. I have used the touchesMoved method(Swift 2). Below is my code override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { super.touchesBegan(touches as Set<UITouch>, withEvent: event) let touch = touches.first if (touch!.view) == (moveLabel as UIView) // moveButton is my label { location = touch!.locationInView(self.view)

When do adjustsFontSizeToFitWidth or boundingRectWithSize change the context.actualScaleFactor?

笑着哭i 提交于 2020-01-10 05:03:49
问题 When does the actualScaleFactor of an NSStringDrawingContext change? The documentation says: "If you specified a custom value in the minimumScaleFactor property, when drawing is complete, this property contains the actual scale factor value that was used to draw the string." My code: myButton.titleLabel!.font = UIFont(name: "AmericanTypewriter-Bold", size: 40) myButton.titleLabel?.adjustsFontSizeToFitWidth = true myButton.setTitle("\(textString)", forState: .Normal) let attributes =

Read More/Less with Swift 3

烈酒焚心 提交于 2020-01-09 10:33:49
问题 I want to add " Read more " at the end of the paragraph. When I click on the "Read more" text, it should be expand and display " Less " at the end. The texts will be collapsed when click on "Less" text. I find many sample work in google. But, I don't understand clearly and most projects are implemented with Objective-C. I also find it in youtube. I would like know very sample code to implement this with Swift 3 . Can I implement without using any additional library? Please help me. 回答1:

AutoLayout multiline UILabel cutting off some text

烂漫一生 提交于 2020-01-09 06:20:29
问题 I'm trying to learn auto layout, finally thought I was getting the hang on it when this happened. I'm playing about with prototype cells and labels. I'm trying to have a Title, titleLbl - blue box in picture Money, moneyLbl - green box in picture Subtitle / Description, subTitleLbl - red box in picture So far I have this: What I want to achieve is: The green box should always display on 1 line fully The value inside the green box should be centred based on the blue box The blue box will take

Use multiple font colors in a single label

白昼怎懂夜的黑 提交于 2020-01-08 17:09:10
问题 Is there a way to use two, or even three font colors in a single label in iOS? If the text "hello, how are you" were used as an example, the "hello," would be blue, and the "how are you" would be green? Is this possible, it seems easier than creating multiple labels? 回答1: Reference from here. First of all initialize of you NSString and NSMutableAttributedString as below. var myString:NSString = "I AM KIRIT MODI" var myMutableString = NSMutableAttributedString() In ViewDidLoad override func

小总结

烂漫一生 提交于 2020-01-07 22:13:21
本文目录 0.UIView常用的属性和操作 0_1.UIView常见的属性 0_2.UIView状态 0_3.UIView常用的方法 1.文本框UITextField和文本视图UITextView 1_1.文本框UITextField(几乎包含了iOS控件的所有的通用属性) 1_2.文本视图UITextView 1_3.键盘输入的处理程序 2.标签UILabel和按钮UIButton 2_1.标签UILabel 2_2.按钮UIButton 3.滑块UISlider、步进UIStepper和图像UIImageView 3_1.滑块UISlider 3_2.步进UIStepper 3_3.图像UIImageView 3_4.图片浏览器 4.开关控件UISwitch和分段控件UISegmentedControl 4_1.开关控件UISwitch 4_2.分段控件UISegmentedControl 4_3.图片排序 5.工具栏UIToolBar 5_1.工具栏UIToolBar的使用 5_2.UIBarButtonItem 说明: 这个专题,是介绍了一些常用的普通空间的属性和使用,包括:UITextField、UITextView、UILabel、UIButton、UISlider、UIStepper、UIImageView、UISwitch、UISegmentedControl

Program crashes when adding NSMutableArray of strings to a UILabel

二次信任 提交于 2020-01-07 08:49:12
问题 When I add this array of strings to the summaryText UILabel it crashes. Please let me know how to fix this. NSMutableArray *arr = [[NSMutableArray alloc]init]; arr = [Singleton getArray]; NSString *str = [arr componentsJoinedByString:@"\n"]; summaryText.text = str; This is what was brought up when i command clicked summaryText @implementation TotalViewController @synthesize tax,taxLabel,total,totalLabel,final,finalLabel,fiveLabel,threeLabel,twoLabel,five,three,two, points, pointsLabel

How to set label according to text but i want background color also [closed]

女生的网名这么多〃 提交于 2020-01-07 08:35:37
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . How to set UILabel according to text but I want backGroundColor also in it, if text is small then it will display background small label with background color black and text and vice-versa.How to do? In image the

How to make UILabel and UITextField font size to be relative to screen size

喜夏-厌秋 提交于 2020-01-07 05:43:05
问题 I have a view controller which has a text field and label and I have set height constraint for text field and label and so I feel font size is not relative to the screen I believe. How can I make this items' font size to be relative to the screen size? 回答1: You can manually change UIlabel or UITextfield font in viewDidLayoutSubviews method of your ViewController or layoutSubviews method of your superView . Like this: CGRect screenSize = [UIScreen mainScreen].bounds; textField.font = [UIFont

How to make UILabel and UITextField font size to be relative to screen size

本秂侑毒 提交于 2020-01-07 05:42:12
问题 I have a view controller which has a text field and label and I have set height constraint for text field and label and so I feel font size is not relative to the screen I believe. How can I make this items' font size to be relative to the screen size? 回答1: You can manually change UIlabel or UITextfield font in viewDidLayoutSubviews method of your ViewController or layoutSubviews method of your superView . Like this: CGRect screenSize = [UIScreen mainScreen].bounds; textField.font = [UIFont