How to set letter spacing of UITextField

前端 未结 7 908
[愿得一人]
[愿得一人] 2021-01-30 12:55

I have an app in which the user has to type a four digit pin code. All digits have to be at a set distance from each other.

Is there a way to do this if the PinTex

7条回答
  •  孤街浪徒
    2021-01-30 13:22

    Use the defaultTextAttributes property of UITextField. It will handle the conversion to NSAttributedString for you and apply the attributes you set. For example:

        NSMutableDictionary *attrs = [self.textField.defaultTextAttributes mutableCopy];
    [attrs addEntriesFromDictionary:@{
        NSKernAttributeName: @18,
        NSUnderlineColorAttributeName: [UIColor grayColor],
        NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle | NSUnderlinePatternDash)
    }];
    self.textField.defaultTextAttributes = attrs;
    

提交回复
热议问题