Question: swift 2 character limit in a label ( string )

Question

swift 2 character limit in a label ( string )

Answers 1
Added at 2017-01-02 20:01
Tags
Question

I have a converter app.

converter

I want the label to only go up to a 5 character limit based on a string. This is the code I have so far.( var calculateArea is the string linked to the UILabel ). Any help will be appreciated.

@IBOutlet weak var displayLabel: UILabel!
var calculateArea: String!
let maxDigits:Int = 5



func StringLimit() -> String {
    calculateArea.characters.count <= maxDigits

    return calculateArea
}
Answers
nr: #1 dodano: 2017-01-03 13:01

see if that helps you

func StringLimit(str:String, remove:Int)->String
{
    var result = str
    let range = result.index(result.endIndex, offsetBy: -remove)..<result.endIndex
    result.removeSubrange(range)

    return result
}

print(StringLimit(str:"today",remove:2)) //tod
Source Show
◀ Wstecz