Calculating multiline text height for UILabel/UITableViewCell: different results when calculating vs actual drawing

Of course, the solution is obvious 30 seconds after posting. Maybe useful to others too… The size by sizeWithFont: was correct. The sizes I calculated in the above way were incorrect, because [label sizeToFit] reduces the width of the label’s frame. At subsequent calls to the same code, it started off with the frame that … Read more

iOS – How to achieve emboss effect for the text on UILabel?

UPDATE FOR iOS 7.0 In iOS 7.0, Apple added a new attribute, NSTextEffectAttributeName, for attributed strings. If your deployment target is iOS 7.0 or later, you can set this attribute to NSTextEffectLetterpressStyle to draw an attributed string in an embossed style. ORIGINAL I can’t say for certain how Apple draws the embossed text. It looks … Read more

UIButton that resizes to fit its titleLabel

Swift 4.x version of Kubba’s answer: Need to Update Line Break as Clip/WordWrap/ in Interface builder to corresponding buttons. class ResizableButton: UIButton { override var intrinsicContentSize: CGSize { let labelSize = titleLabel?.sizeThatFits(CGSize(width: frame.width, height: .greatestFiniteMagnitude)) ?? .zero let desiredButtonSize = CGSize(width: labelSize.width + titleEdgeInsets.left + titleEdgeInsets.right, height: labelSize.height + titleEdgeInsets.top + titleEdgeInsets.bottom) return desiredButtonSize } … Read more

UITableViewCell makes label’s background clear when highlighted

You need to subclass UITableViewCell and override the following two methods: Objective-C: – (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { UIColor *backgroundColor = self.myLabel.backgroundColor; [super setHighlighted:highlighted animated:animated]; self.myLabel.backgroundColor = backgroundColor; } – (void)setSelected:(BOOL)selected animated:(BOOL)animated { UIColor *backgroundColor = self.myLabel.backgroundColor; [super setSelected:selected animated:animated]; self.myLabel.backgroundColor = backgroundColor; } Swift override func setSelected(_ selected: Bool, animated: Bool) { let color = myLabel.backgroundColor … Read more

How to align UILabel text from bottom?

Swift 4.2 version using the contentMode property to set top and bottom: class VerticalAlignedLabel: UILabel { override func drawText(in rect: CGRect) { var newRect = rect switch contentMode { case .top: newRect.size.height = sizeThatFits(rect.size).height case .bottom: let height = sizeThatFits(rect.size).height newRect.origin.y += rect.size.height – height newRect.size.height = height default: () } super.drawText(in: newRect) } } … Read more

how do I change text in a label with swift?

Swift uses the same cocoa-touch API. You can call all the same methods, but they will use Swift’s syntax. In this example you can do something like this: self.simpleLabel.text = “message” Note the setText method isn’t available. Setting the label’s text with = will automatically call the setter in swift.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)