我希望有多行的UITextField,在对这个问题进行了快速的google搜索之后,我发现我应该使用TextView,所以当我需要多行时,我确实将代码转换为使用UITextView。我的视图还有我想保留的另一行textField。
为了使我的TextView看起来像TextField,我不得不添加代码来设置边框和radius,但是它们在iOS7上看起来有点不同。有没有人知道:
如果要继续使用textfield来处理多行文本,我会全神贯注地使用它。
诚挚的问候,
发布于 2014-06-14 18:14:55
我用这个:
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;
params中的细微差别使它看起来更像UITextField(我希望如此)。
发布于 2014-02-07 13:13:01
我用这个:
#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];
}
得到一个好的结果。
发布于 2014-02-02 20:06:40
我有一个小的UITextView子类,它在iOS 7中给出了与UITextField相同的外观
接口为空:
@interface MyTextView : UITextView
@end
该实现覆盖“可编辑”属性的初始化和setter:
@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
https://stackoverflow.com/questions/20790907
复制相似问题