gpt4 book ai didi

ios - 代码 : How to Add Left and Right Padding on Text Field?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:45:50 27 4
gpt4 key购买 nike

我有这个 .h 代码:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *fieldEmail;
@property (strong, nonatomic) IBOutlet UITextField *fieldPassword;
@property (strong, nonatomic) IBOutlet UILabel *titleLogin;

- (IBAction)buttonRegister;
- (IBAction)buttonLogin;
- (IBAction)loginFacebook;
- (IBAction)loginTwitter;

@end

这是我的 .m 代码:​​

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[_fieldEmail setFont:[UIFont fontWithName:@"ABeeZee-Regular" size:14]];
[_titleLogin setFont:[UIFont fontWithName:@"Raleway-ExtraLight" size:28]];

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)buttonRegister {
}

- (IBAction)buttonLogin {
}

- (IBAction)loginFacebook {
}

- (IBAction)loginTwitter {
}
@end

现在,我想要做的是在这两个文本字段的左侧和右侧添加填充:fieldEmailfieldPassword 所以它有一些空间,因为我放了一个图像作为两个文本字段的背景。

我试图在 - (void)viewDidLoad 下的 .m 文件中添加此代码:

UIView *fieldEmail = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
[UITextField setLeftViewMode:UITextFieldViewModeAlways];
[UITextField setLeftView:fieldEmail];

但是我的 XCode 给了我这个错误信息:

no known class method for selector 'setLeftViewMode'
no known class method for selector 'setLeftView'

顺便说一下,我使用的是 XCode 4.6.3。这个版本有特殊的代码来在文本字段上添加填充吗?谢谢。

最佳答案

leftViewModeleftViewUITextField 的属性,不是类方法。您需要将它们分配给实例。

yourTextField.leftViewMode = UITextFieldViewModeAlways;
yourTextField.leftView = fieldEmail;

关于ios - 代码 : How to Add Left and Right Padding on Text Field?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18682390/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com