【发布时间】:2014-03-31 03:30:06
【问题描述】:
我有一个 UItextField,在 leftView 上有一个图像,但我需要 UITextField 与中心对齐,并且在左视图中,它向右移动。 代码如下:
self.usernameField = [[UITextField alloc]initWithFrame:CGRectMake(0, 150, self.view.frame.size.width, 50)];
self.usernameField.placeholder = @"E-mail";
[self.usernameField setFont:[UIFont ralewayRegularFontWithSize:20]];
[self.usernameField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
[self.usernameField setKeyboardType:UIKeyboardTypeEmailAddress];
[self.usernameField setBackground:[UIImage imageNamed:@"background_placeholder"]];
[self.usernameField setTextColor:[UIColor whiteColor]];
[self.usernameField setTextAlignment:NSTextAlignmentCenter];
[self.usernameField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[self.usernameField setBorderStyle:UITextBorderStyleNone];
[self.usernameField setBackgroundColor:[UIColor clearColor]];
[self.usernameField setLeftViewMode:UITextFieldViewModeAlways];
self.usernameField.leftView = [[UIView alloc] init];
[self.usernameField.leftView setFrame:CGRectMake(0, 0, 50, 30)];
[self.usernameField.leftView setBackgroundColor:[UIColor clearColor]];
UIImageView *imgViewMail = [[UIImageView alloc] initWithFrame:CGRectMake(20, 5, 25, 25)];
[imgViewMail setImage:[UIImage imageNamed:@"mail_icon"]];
[self.usernameField.leftView addSubview:imgViewMail];
[self.view addSubview:self.usernameField];
编辑 - 图片说明问题。 - 两个 First textFields
【问题讨论】:
-
您可以发布任何图片来确定确切的问题吗?
-
k 你说 E-mail 和 senha 应该居中对吗?
-
它应该居中,向左更多像素。
标签: ios objective-c uitextfield alignment