UITextView模仿UITextField [基本圆角文本字段]

use*_*681 4 colors uitextfield uitextview ios7

我希望UITextField有多行,在这个问题上快速谷歌之后我发现我应该使用TextView所以当我想要多行时,我确实切换了我的代码以使用UITextView.我的视图仍然有其他一行textField我想保留.

为了使我的TextView看起来像TextField,我不得不添加代码来设置边框和半径,但它们在iOS7上看起来有点不同.有人知道吗:

  • UITextField边框的颜色是什么?当启用和禁用时,我都可以发送我的textview来匹配它.
  • 什么是TextField角落的半径.
  • UITextField被禁用时的背景颜色是什么[附图显示文本字段在禁用时具有较浅的灰色阴影]?因此,当我禁用用户交互时,我可以将文本视图设置为相同的颜色.

如果有继续使用文本字段的多行文字,我都是耳朵,我切换使用它.

最好的祝福,

在此输入图像描述

Ham*_*ato 7

我用这个:

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;
Run Code Online (Sandbox Code Playgroud)

params的微小差异使它看起来更像UITextField(我希望).


Pat*_*ckV 0

我有一个 UITextView 的小子类,它在 iOS 7 中与 UITextField 具有相同的外观

界面为空:

@interface MyTextView : UITextView
@end
Run Code Online (Sandbox Code Playgroud)

该实现覆盖了“可编辑”属性的初始化和设置器:

@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
Run Code Online (Sandbox Code Playgroud)