- (BOOL)textField:(UITextField )textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString )string {
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:textField.placeholder];
[attributedString addAttribute:NSKernAttributeName
value:@(1.5)
range:NSMakeRange(0,textField.placeholder.length)];
textField.attributedPlaceholder = attributedString;
return YES;
}
我尝试过这种方法但不幸的是,该方法只能在UITextField中输入,但我想在UITextField中输入任何内容之前。占位符在字符之间应具有相等的间距。 提前谢谢
答案 0 :(得分:0)
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableAttributedString *attributedString ;
attributedString = [[NSMutableAttributedString alloc] initWithString:self.firsttextfield.placeholder];
[attributedString addAttribute:NSKernAttributeName
value:@(1.5)
range:NSMakeRange(0,self.firsttextfield.placeholder.length)];
self.firsttextfield.attributedPlaceholder = attributedString;
self.secondtexfield.attributedPlaceholder = attributedString;
}
我只是将上面的行保留在viewdidload中,而不是将它们保留在textfield函数中。希望它有效。
答案 1 :(得分:0)
默认情况下没有属性,您可以这样做。
方法1 : NSString * textToPrint = [NSString stringWithFormat:@“tehrsygghdBUY”];
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:textToPrint];
[attributeString addAttribute:NSForegroundColorAttributeName
value:[UIColor clearColor]
range:NSMakeRange(0, 1)]; // change it of spacing
[attributeString addAttribute:NSForegroundColorAttributeName
value:[UIColor LightgrayColor ]
range:NSMakeRange(3, [attributeString length]-3)];
[_buyButtonView setAttributedTitle:attributeString forState:UIControlStateNormal];
方法2 :
抱歉,对于textfiled,你必须提供一个uiview作为文本字段的超级视图。并为textfield提供透明色。然后将5到10品脱作为原点x(文本字段的框架)