Viblo
  • Posts
  • Questions
  • Discussions
Announcements
No announcement yet.
All Announcements

Thanh Nguyen

@thanhfnx

Report
  • Posts
  • Series
  • Questions
  • Answers
  • Clips
  • Followings
  • Followers
  • Tags
  • Reputations
  • Communication

NSAttributext iOS

Thanh Nguyen
Answered Mar 5th, 2019 12:15 PM

Các font chữ tiếng Nhật thường bị như vậy. Cách khắc phục: Dùng custom class cho label, button... kiểu như này để tăng intrinsicContentSize height lên.

class CustomLabel: UILabel {

    open override var intrinsicContentSize: CGSize {
        var size = super.intrinsicContentSize
        size.height += (0.275 * font.pointSize)
        return size
    }

    override func sizeToFit() {
        super.sizeToFit()
        frame.size = intrinsicContentSize
    }

}
class CustomButton: UIButton {

    override func layoutSubviews() {
        super.layoutSubviews()
        titleLabel?.sizeToFit()
        if let titleLabel = self.titleLabel {
            var frame = titleLabel.frame
            let adjustHeight = 0.275 * titleLabel.font.pointSize
            frame.size.height += adjustHeight
            frame.origin.y -= (adjustHeight / 2)
            titleLabel.frame = frame
        }
    }

}
+2

Total post views

40.0K

Reputations

912

Following tags

0

Following users

0

Followers

40

Posts

41

Clips

0

Total questions

0

Total answers

1

Organization


Have no organizations yet.

Posts tendency


Resources

  • Posts
  • Organizations
  • Questions
  • Tags
  • Videos
  • Authors
  • Discussions
  • Recommend System
  • Tools
  • Machine Learning
  • System Status

Services

  • Viblo CV Viblo Code
  • Viblo CV Viblo CV
  • Viblo CTF Viblo CTF
  • Viblo Learning Viblo Learning

Mobile App

Get it on Google Play Download on the App Store
QR code

Links

  • Atom Icon

© 2021 Viblo. All rights reserved.

  • About Us
  • Feedback
  • Help
  • FAQs
  • RSS
  • Terms
  • DMCA.com Protection Status