ios UITextField 設置光標的起始位置, 讓其右移

由於UITextField的光標位置 是緊貼左邊框的, 看起來不美觀,如下圖
這裏寫圖片描述

可以通過設置UITextField的leftView 讓其右移 如下圖:
這裏寫圖片描述

代碼如下:
UITextField *textField = [[UITextField alloc] init];
textField.delegate = self;
textField.backgroundColor = [UIColor whiteColor];
textField.layer.cornerRadius = 5;
textField.layer.masksToBounds = YES;
[self.bgView addSubview:textField];
UILabel * leftView = [[UILabel alloc] initWithFrame:CGRectMake(10,0,7,26)];
leftView.backgroundColor = [UIColor clearColor];
textField.leftView = leftView;
textField.leftViewMode = UITextFieldViewModeAlways;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章