0

I have to do the following calculation:

I have to count how many characters may be put in one line of UILabel(with spaces). In my app I have big text and I have to count how many characters of this text may be put in the first line of UILabel.

I've found different similar solution, for example how to count number of rows in UILabel, etc. But I can't find anything according to my question, could you please help me?

Community
  • 1
  • 1
Yuri Chukhlib
  • 120
  • 11
  • 1
    http://stackoverflow.com/questions/25193520/determine-the-maximum-number-of-characters-a-uilabel-can-take OR http://stackoverflow.com/questions/23290960/how-to-count-how-many-characters-can-come-in-a-uilabel-line – Rohit Khandelwal Dec 23 '15 at 11:37
  • to handle big text for label you can have different solution – Arslan Asim Dec 23 '15 at 13:36

1 Answers1

0

Maybe you could approach the problem in a different way. You can decide how many characters you allow in one label.

let limitLength = whatever length you want to allow

func textField(username: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
    guard let text = username.text else { return true }
    let newLength = text.characters.count + string.characters.count - range.length
    return newLength <= limitLength
}
Alex Zanfir
  • 573
  • 4
  • 13