0

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];
4

3 回答 3

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 Reference 导入您的项目并添加

# 导入 <QuartzCore/QuartzCore.h>

到您的 ViewController.m 以使用边框颜色和边框宽度。

于 2013-05-22T09:39:44.903 回答
0

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

Apple 有一个关于以这种方式制作简单应用程序的教程

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

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

您将以与您使用的其他属性相同的方式访问这些属性:

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

对于边框颜色,请参阅UITextView 周围边框的答案

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

于 2013-05-22T02:11:49.657 回答
0

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

myTextField.layer.borderColor = [UIColor whileColor];

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

于 2013-05-22T03:20:43.020 回答