輸入框一般有無邊框(空白輸入框),全邊框(矩形輸入框),加邊框很簡單,只需要設置UITextField的layer.borderColor屬性和layer.borderWidth屬性就可以了,如果要實現只帶底部框線的輸入框就不太好弄了,百度了一下找到了一個最笨也是挺不錯的一個方法,那就是在下面直接給它加一條線就可以了。示例代碼:
UITextField *passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(60, 120, 140, 23)];
passwordTextField.font = FONT(15);
passwordTextField.placeholder = @"請輸入密碼";
[passwordTextField setSecureTextEntry:YES];
[self.view addSubview:passwordTextField];
UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0,passwordTextField.height - 1, passwordTextField.width, 1)];
lineView.backgroundColor = [UIColor orangeColor];
[passwordTextField addSubview:lineView];
順便附上效果圖: