skip to Main Content

I want the UILabel text to be larger, but when I change value_row_height, there is no change in size.

var value_row_x = 30
var value_row_y = 100
var value_row_height = 320    
var value_row_width = 30


let heart_rate_title_UILabel = UILabel(frame: CGRect(x: value_row_x, y: value_row_y, width: value_row_width, height: value_row_height ))
heart_rate_title_UILabel.center = CGPoint( x: value_row_x + value_row_width / 2, y: value_row_y + value_row_height/2 )
heart_rate_title_UILabel.textAlignment = .left
heart_rate_title_UILabel.text = "heart: "
heart_rate_title_UILabel.sizeToFit()
self.view.addSubview( heart_rate_title_UILabel)

UPDATE:
I added following code, but size failed to change…
heart_rate_title_UILabel.font = label.font.withSize(20)
heart_rate_title_UILabel.minimumScaleFactor = 0.1 //or whatever suits your need
heart_rate_title_UILabel.adjustsFontSizeToFitWidth = true
heart_rate_title_UILabel.lineBreakMode = .byClipping
heart_rate_title_UILabel.numberOfLines = 0

2

Answers


  1. Chosen as BEST ANSWER

    This worked jim-dandy....

                value_row_y -= 10          
                value_row_x += 45 + inter_value_gap_pix       // + width of heart rate value
                let title_UILabel = UILabel(frame: CGRect(x: value_row_x, y: value_row_y, width: value_row_width, height: value_row_height ))
                title_UILabel.center = CGPoint( x: value_row_x + value_row_width / 2, y: value_row_y + value_row_height/2 )
                title_UILabel.textAlignment = .left
                title_UILabel.text = " RSP: "
                self.view.addSubview( title_UILabel)
                // set font height to biggest (ie. label height)...
                    title_UILabel.numberOfLines = 1;
                    title_UILabel.font = title_UILabel.font.withSize(30)
    

  2. You are changing the physical height of the label. You are not saying anything about what the text size should be. Text size is a matter of setting the label’s font (which includes size).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search