uilabel

\n not working in UIlabel

点点圈 提交于 2019-12-12 08:40:29
问题 I've seen similar questions here, but still can figure out why it's not working. How to add line break (in other words add new paragraph) in multiline UIlabel? I have a label with a lot of text, lbl.numberOfLines = 0; lbl.sizeToFit; but I'm still getting something like this: "Some text here\nAnd here I want new line" Thank you 回答1: UILabel won't respect \n, You can use option-return (in Interface builder) to force where you want a line break. You can use a UIWebView in place of the label and

Swift 3 - Adjust Font Size to Fit Width, Multiple Lines

心已入冬 提交于 2019-12-12 08:36:51
问题 I have a UILabel and it is set to 42.0 pt font, and the width of the label is set using autoconstraints based on factors other than the label itself (aka the things to the right and left of the label determine the label's width). I would like to auto-adjust the font size to fit the width of the label, however also break to two lines when it can. Similar to this: I know you can adjust the font size to fit the width of the label, but only when the number of lines is set to 1. How would I

Setting text to fit the size of a UILabel and centre in SWIFT

天大地大妈咪最大 提交于 2019-12-12 08:26:39
问题 I'm trying to set text to fit the size of a UILabel and also be centred. I am doing this programmatically. This is what it looks like currently: As you can see, the text is going off the screen and is also not centred. This is my code: let questions = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac faucibus tellus." questionsLabel = UILabel(frame: CGRectMake(10, 10, questionsView.frame.size.width - 20, 80)) questionsLabel.text = questions questionsLabel.font = UIFont(name:

AutoLayout and UILabel resize animation not working properly on device rotation

依然范特西╮ 提交于 2019-12-12 07:48:47
问题 i have a strange problem on a very simple task. I needs a very small setup to reproduce the problem: |--------------------------------------| | Parent View | | | ||------------------------------------|| || UILabel || ||------------------------------------|| | | | | ||------------------------------------|| || UIView || ||------------------------------------|| | | | | |--------------------------------------| In the example above we have a parent view with 2 subviews --> A UILabel and a simple

Pre-rendering, Pre-blending, CoreGraphics, CALayers?

别等时光非礼了梦想. 提交于 2019-12-12 06:06:24
问题 I have 200+ uiLabels added to a long (92000px) uiScrollView. I am getting the impression from some of the QAs that one option to improve performance is to pre-render the whole view into one? I basically add my uiLabels in a for loop inside ViewDidLoad to a scrollview. Could someone give me a few ideas for how you could go about rendering all those uilabels to a single layer? then add that layer to the uiScrollView? (I mention single Layer, I don't know anything about layers, I am just making

dynamic cell height in UITableView with AutoLayout

谁说胖子不能爱 提交于 2019-12-12 05:59:44
问题 I have been trying to get this tutorial dynamic-cell-height to work in ios8 for days now and can't figure out what is going on. It works in ios7 on the iphone and it works in both ios7 & ios8 on the iPAD but it doesn't work on any the iphone on ios8. I think the problem lies in how and when the labels are being created within the cell. I have the following code in the controller: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.dbManager = [

About trouble of device rotation using MTLabel

…衆ロ難τιáo~ 提交于 2019-12-12 05:48:44
问题 I have to use MTLabel Class for line-spacing of UILabel. ( refered sample code : https://github.com/Tuszy/MTLabel ) But Some problems exists. I'm making a iPad App. This app is able to rotate - landscape or portrait. I put UILabel and MTLable objects on view without IB. Whenever orientation of device is changed, width of text also changed. This result is not what I want. My code : #import "MTLabel.h" . - (void)viewDidLoad { [super viewDidLoad]; MTLabel *TitleFont = [[MTLabel alloc]

How to display XML parsed data in a label iOS

半世苍凉 提交于 2019-12-12 05:47:51
问题 I have 2 classes: XMLParser and ViewController . All the code for the parsing process is in the XMLParser . I call the date being parsed in ViewController and display it in Command Output window using NSLog . Now my problem is I can't seem to get the data to be displayed in a UILabel called "profilesLabel". In the ViewController is a UIButton called "showProfilesButton" which should display the data in profilesLabels text. See the attempted code in ViewController.m. Any help would be

Set frame (CGRect) per devices by count of characters - Swift 3

不羁岁月 提交于 2019-12-12 05:28:40
问题 I'm creating label and characters, I want set frame (X, Y and width) of UILabel by characters and Y-axis is constant of all devices, so how can I set center of X-axis and controlling by count of characters, and width (50) gets smaller and bigger per device ?? This my code : func createTarget(id: Int) { listdata = dbHelpr.getDatabase(rowId: id) for data in listdata { let lengthOfChar : CGFloat = data.ans.length let targetSize : CGFloat = self.view.frame.width / 2 var xAxis : CGFloat = self

Updating UILabel text when variable changes

核能气质少年 提交于 2019-12-12 04:44:54
问题 I've got a UIControl class and need to do some calculation based on UIImageView location which can be moved with touchesBegan and touchesMoved (everything inside this class). Than I would like to display it as a UILabel which I've created programmatically. class control : UIControl{ ... let leftControl: UIImageView = UIImageView(image: UIImage(named: "left-control")) ... func leftValue() -> String{ var leftValue : String = "0.0" leftValue = "\(leftControl.center.x)" return leftValue } } and