Colors UITextView模拟UITextField[用于基本圆角文本字段]
我想让UITextField有多行,在快速搜索了这个问题后,我发现我应该使用TextView,所以当我需要多行时,我确实将代码切换为使用UITextView。我的视图还有另外一行文本字段要保留 为了使我的TextView看起来像TextField,我必须添加代码来设置边框和半径,但它们在iOS7上看起来有点不同。有谁知道:Colors UITextView模拟UITextField[用于基本圆角文本字段],colors,ios7,uitextfield,uitextview,Colors,Ios7,Uitextfield,Uitextview,我想让UITextField有多行,在快速搜索了这个问题后,我发现我应该使用TextView,所以当我需要多行时,我确实将代码切换为使用UITextView。我的视图还有另外一行文本字段要保留 为了使我的TextView看起来像TextField,我必须添加代码来设置边框和半径,但它们在iOS7上看起来有点不同。有谁知道: UITextField边框的颜色是什么?当同时启用和禁用时,我可以发送文本视图以匹配它 TextField角的半径是多少 禁用UITextField时的背景色是什么[所附图
- UITextField边框的颜色是什么?当同时启用和禁用时,我可以发送文本视图以匹配它
- TextField角的半径是多少
- 禁用UITextField时的背景色是什么[所附图片显示禁用时文本字段的灰色较浅]?因此,当我禁用用户交互时,我可以将文本视图设置为相同的颜色
我有一个小的UITextView子类,它在iOS 7中提供了与UITextField相同的外观 界面为空:
@interface MyTextView : UITextView
@end
该实现覆盖“可编辑”属性的初始化和设置程序:
@implementation MyTextView
//================================================================================
- (id) initWithFrame: (CGRect) frame
{
self = [super initWithFrame:frame];
if (self)
{
[self commonInit];
}
return self;
}
//================================================================================
- (id) initWithCoder: (NSCoder *) aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
[self commonInit];
}
return self;
}
//================================================================================
- (void) commonInit
{
self.layer.borderWidth = 1.0f;
self.layer.borderColor = [[UIColor colorWithRed:232.0/255.0
green:232.0/255.0 blue:232.0/255.0 alpha:1] CGColor];
self.layer.cornerRadius = 6;
}
//================================================================================
- (void) setEditable: (BOOL) editable
{
[super setEditable:editable];
if (editable)
{
self.backgroundColor = [UIColor whiteColor];
}
else
{
self.backgroundColor = [UIColor colorWithRed:250.0/255.0
green:250.0/255.0 blue:250.0/255.0 alpha:1];
}
}
//================================================================================
@end
我用这个:
#import <QuartzCore/QuartzCore.h>
-(void) textViewLikeTextField:(UITextView*)textView
{
[textView.layer setBorderColor:[[UIColor colorWithRed:212.0/255.0
green:212.0/255.0
blue:212.0/255.0
alpha:1] CGColor]];
[textView.layer setBorderWidth:1.0f];
[textView.layer setCornerRadius:7.0f];
[textView.layer setMasksToBounds:YES];
}
textView.layer.borderColor = [[UIColor colorWithRed:215.0 / 255.0 green:215.0 / 255.0 blue:215.0 / 255.0 alpha:1] CGColor];
textView.layer.borderWidth = 0.6f;
textView.layer.cornerRadius = 6.0f;
#导入
-(void)textViewLikeTextField:(UITextView*)textView
{
[textView.layer setBorderColor:[[UIColor颜色与红色:212.0/255.0]
绿色:212.0/255.0
蓝色:212.0/255.0
alpha:1]CGColor]];
[textView.layer setBorderWidth:1.0f];
[textView.layer setCornerRadius:7.0f];
[textView.layer setMasksToBounds:是];
}
并得到一个好的结果。我用这个:
#import <QuartzCore/QuartzCore.h>
-(void) textViewLikeTextField:(UITextView*)textView
{
[textView.layer setBorderColor:[[UIColor colorWithRed:212.0/255.0
green:212.0/255.0
blue:212.0/255.0
alpha:1] CGColor]];
[textView.layer setBorderWidth:1.0f];
[textView.layer setCornerRadius:7.0f];
[textView.layer setMasksToBounds:YES];
}
textView.layer.borderColor = [[UIColor colorWithRed:215.0 / 255.0 green:215.0 / 255.0 blue:215.0 / 255.0 alpha:1] CGColor];
textView.layer.borderWidth = 0.6f;
textView.layer.cornerRadius = 6.0f;
参数之间的细微差别使它看起来更像UITextField(我希望如此)。这是我启用UITextView后得到的最接近的结果
[yourTextView.layer setBorderColor:[[[UIColor lightGrayColor] colorWithAlphaComponent:0.2] CGColor]];
[yourTextView.layer setBorderWidth:2.0];
yourTextView.layer.cornerRadius = 5;
yourTextView.clipsToBounds = YES;
yourTextView.textColor = [UIColor lightGrayColor];
有人知道这个问题吗?为什么不使用单行UITextView而不是UITextField呢。通过这种方式,你可以定制两者的外观相同。这在视网膜显示上看起来更精确。我使用了这个,但下面的@Hamhog修改更精确。