uilabel

UIView viewwithtag method in swift [closed]

孤人 提交于 2020-01-01 04:08:07
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I'm trying to learn some swift. I programmatically add labels. I want to change their properties later. the viewwithtag method returns a UIView, how to I access my UILabel from this? cheers 回答1: You need to use a typecast. This code will do it: if let theLabel = self.view

How Can I indent only first line of multiline UILabel in iOS?

余生颓废 提交于 2020-01-01 02:43:11
问题 I want to add an image in start of UILabel. Label is multiline. If I use contentInset, it indent the whole label but I want to indent first line only. I have tried this so far, this doesn't work for me. UIEdgeInsets titleInsets = UIEdgeInsetsMake(0.0, 40.0, 0.0, 0.0); valueLabel.contentInset = titleInsets; It should look like this. 回答1: @DavidCaunt suggestion worked for me. I am sharing code here. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; style

How to align UILabel text from bottom?

好久不见. 提交于 2019-12-31 11:02:43
问题 How the UILabel can be aligned from bottom. Let say, my label can hold three line of text.If the input text is single line, then this line should come bottom of the label.Please refer the below image for better understanding. The orange area is the full frame of label.Currently it has one line and it is aligned center. So what I want is, it should always aligned bottom regardless of how many lines. Please suggest your ideas. Thank you. 回答1: Here are two ways of doing that... 1. First set

iOS7 UILabel to adopt same tintColor as window

百般思念 提交于 2019-12-31 10:40:54
问题 I know that for elements of classes UIButton and UIBarButtonItem they automatically assume window.tintColor as the main colour, which results of an immediate change in case I set a new tintColor to window at any time in the app. I was wondering if there is any way to make UILabel elements to follow the same pattern, where once created they automatically assumer its default colour as window.tintColor and if changing window.tintColor at any time within my app runtime would also result in

Cannot assign a value of type “String” to type “UILabel” in swift

南楼画角 提交于 2019-12-31 06:54:07
问题 I'm making a program that 's about a math test random generator. But while I was creating a random operation. I used arc4random_uniform() to create a random number. Here's the function. func generateQuestion() { var randomoperation:UInt32 = arc4random_uniform(3) if randomoperation == 0 { operation = "+" } if randomoperation == 1 { operation = "-" } if randomoperation == 2 { operation = "X" } if randomoperation == 3 { operation = "/" } } This creates the error "Cannot assign a type of value

Change font size for iPad Pro in steps

狂风中的少年 提交于 2019-12-31 06:24:44
问题 I have an app, which is intended only for iPad in landscape mode. The screen design is completely done in IB with autolayout. Now I want to achieve the following behaviour: All the labels should have font size 48 when on iPad Pro 12", and for all smaller iPad sizes the font size should be 32. I tried various options in IB with autoshrink and minimum font size, but then the app picks font sizes in between 48 - 32 and gives a random look. But I only want to have 48 for 12" or 32 for all smaller

How to randomize UILabel text each time the view controller is showed

≯℡__Kan透↙ 提交于 2019-12-31 05:27:10
问题 How do I make a label in my ViewController have a diffrent string of text each time the view crontroller is shown? Thanks! I'm using Swift 3 回答1: Assuming you know how to add UILabel to your ViewController , here is quick sample how to pick random text on start: class ViewController: UIViewController { let allTexts = ["Hey", "Hi", "Hello"] @IBOutlet weak var label: UILabel! //get UILabel from storyboard override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.label

Update Label In While Loop Swift

假装没事ソ 提交于 2019-12-30 14:45:44
问题 Correct me if I'm wrong, but when I try to update my label in a while loop it won't update it. Is the reason that the while loop runs too quickly for the label to update within that time so it'll cancel the label from updating? I need a solution to this? I need to be able to update the label straight away? func Download(complete: (canMoveOn: Bool) -> Void) { isDownload = true if (connected!) { Reset() let data = NSData(contentsOfFile: path!)! let buffer = (UnsafeMutablePointer<UInt8>(data

Update Label In While Loop Swift

别说谁变了你拦得住时间么 提交于 2019-12-30 14:44:28
问题 Correct me if I'm wrong, but when I try to update my label in a while loop it won't update it. Is the reason that the while loop runs too quickly for the label to update within that time so it'll cancel the label from updating? I need a solution to this? I need to be able to update the label straight away? func Download(complete: (canMoveOn: Bool) -> Void) { isDownload = true if (connected!) { Reset() let data = NSData(contentsOfFile: path!)! let buffer = (UnsafeMutablePointer<UInt8>(data

UILabel truncate tail and skip not complete word

社会主义新天地 提交于 2019-12-30 09:29:43
问题 I have a single line UILabel . It has width = screen width and the content now is (the content of UILabel can change) You have 30 seconds to make an impression during an interview Currently, my UILabel is truncated tail and the word "duration" is not complete self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail; What I want is I want my UILabel still truncating tail and only display complete word. Like the image below Any help or suggestion would be great appreciated. 回答1: You can do