ios - XCode : How to Add Left and Right Padding on Text Field?
<p><p>我有这个 .h 代码:</p>
<pre><code>#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
</code></pre>
<p>这是我的 .m 代码:</p>
<pre><code>#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
];
];
;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
;
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonRegister {
}
- (IBAction)buttonLogin {
}
- (IBAction)loginFacebook {
}
- (IBAction)loginTwitter {
}
@end
</code></pre>
<p>现在,我要做的是在这两个文本字段的左侧和右侧添加填充: <code>fieldEmail</code> 和 <code>fieldPassword</code> 所以它有一些空间,因为我放了一个图像作为两个文本字段的背景。</p>
<p>我尝试在 <code>- (void)viewDidLoad</code> 下的 .m 文件中添加此代码:</p>
<pre><code>UIView *fieldEmail = [ initWithFrame:CGRectMake(0, 0, 10, 10)];
;
;
</code></pre>
<p>但是我的 XCode 给了我这个错误信息:</p>
<pre><code>no known class method for selector 'setLeftViewMode'
no known class method for selector 'setLeftView'
</code></pre>
<p>顺便说一句,我使用的是 XCode 4.6.3。这个版本是否有特殊代码可以在文本字段上添加填充?谢谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><code>leftViewMode</code> 和 <code>leftView</code> 是 <code>UITextField</code> 的属性,<em>不是类方法</em>。您需要将它们分配给实例。</p>
<pre><code>yourTextField.leftViewMode = UITextFieldViewModeAlways;
yourTextField.leftView = fieldEmail;
</code></pre></p>
<p style="font-size: 20px;">关于ios - XCode : How to Add Left and Right Padding on Text Field?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/18682390/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/18682390/
</a>
</p>
页:
[1]