更改边框线和字体颜色的颜色

时间:2013-05-22 01:55:40

标签: ios objective-c uitextfield

Xcode新手。我有一个黑色轮廓的文本字段,但我希望它是白色的。 字体颜色也需要是白色。 如果能够将输入的文本居中。

由于

到目前为止,这是我的代码:

self.poundsTxt=[[UITextField alloc] initWithFrame:CGRectMake(17, 210, 120, 25)];
self.poundsTxt.borderStyle = UITextBorderStyleLine;
self.poundsTxt.font = [UIFont systemFontOfSize:15];
self.poundsTxt.autocorrectionType = UITextAutocorrectionTypeNo;
self.poundsTxt.keyboardType = UIKeyboardTypeNumberPad;
self.poundsTxt.tag=1;
self.poundsTxt.userInteractionEnabled=YES;
self.poundsTxt.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.poundsTxt.delegate = self;
self.poundsTxt.returnKeyType=UIReturnKeyDone;
[self.view addSubview:self.poundsTxt];

3 个答案:

答案 0 :(得分:1)

要将字体颜色更改为白色并使文本对齐中心,请添加此

self.poundsTxt.textColor = [UIColor whiteColor];
self.poundsTxt.textAlignment=UITextAlignmentCenter;

要将边框颜色更改为白色并为边框添加宽度,请添加此

self.poundsTxt.layer.borderColor = [[UIColor whiteColor]CGColor];
self.poundsTxt.layer.borderWidth=2.0;

导入 Quartz Core Framework 参考您的项目并添加

#import< QuartzCore / QuartzCore.h>

到你的ViewController.m来处理borderColor和borderWidth。

答案 1 :(得分:0)

除非您确实需要在代码中创建UI,否则请使用xib创建视图控制器并使用InterfaceBuilder来布局UI和调整选项。您希望做的许多事情都在Interface Builder中。该项目可能已经为您设置了一对。

Apple已经a tutorial以这种方式创建一个简单的应用程序。

您实际上是在创建一个UITextField,而不是一个UIButton的按钮。 UITextField具有您感兴趣的以下属性:

@property(nonatomic, retain) UIColor *textColor;
@property(nonatomic) NSTextAlignment textAlignment;

您可以使用与您使用的其他属性相同的方式访问它们:

self.poundsTxt.textColor = [UIColor whiteColor];
self.poundsTxt.textAlignment = NSTextAlignmentCenter;

对于寄宿生颜色,请参阅Border around UITextView

的答案

另外,请务必阅读UITextViewUIButtonUIView的文档。

答案 2 :(得分:0)

要为UITextField设置边框颜色,可以设置它的图层属性' 例如: -

myTextField.layer.borderColor = [UIColor whileColor];

确保将QuartzCore框架导入项目并在实现中导入#import <QuartzCore/QuartzCore.h>

相关问题