【问题标题】:Border around UITextViewUITextView 周围的边框
【发布时间】:2011-07-06 20:04:16
【问题描述】:

如何在 UITextView(如 UITextField)周围添加边框?我想允许用户键入多行,但不幸的是 UITextField 不支持这一点。有没有一种简单的方法可以在代码中执行此操作,还是我需要在 Photoshop 中创建一个?

【问题讨论】:

    标签: text uitextfield uitextview border cgrect


    【解决方案1】:
     #import <QuartzCore/QuartzCore.h> 
    

    导入上述框架并将这些行包含在定义 textview 的类中。

    [[self.textview layer] setBorderColor:[[UIColor grayColor] CGColor]];
    [[self.textview layer] setBorderWidth:2.3];
    [[self.textview layer] setCornerRadius:15];
    

    快速解决方案。

    self.textview.layer.borderColor = UIColor.gray.cgColor              
    self.textview.layer.borderWidth = 2.3                
    self.textview.layer.cornerRadius = 15
    

    【讨论】:

    • 要恢复默认吗?
    • @lostintranslation 只是尝试更改边框宽度和角半径的值。
    【解决方案2】:

    快速解决方案:

        var textView = UITextView(frame: CGRectMake(0,0,100,100))
        textView.layer.cornerRadius = 5
        textView.layer.borderColor = UIColor.purpleColor().CGColor
        textView.layer.borderWidth = 1
    

    iOS8无需导入QuarzCore

    【讨论】:

      【解决方案3】:

      解决方案:

      contentView.layer.borderWidth = 2.0f;
      contentView.layer.borderColor = [[UIColor blueColor] CGColor];
      contentView.layer.cornerRadius = 5;
      

      【讨论】:

        【解决方案4】:

        如果您进行快速搜索,您会找到几个答案。示例:

        How to style UITextview to like Rounded Rect text field?

        【讨论】:

        • 这不是贴答案的方法,链接随时可能被破坏。
        猜你喜欢
        • 2015-03-04
        • 2016-02-24
        • 1970-01-01
        • 1970-01-01
        • 2012-10-05
        • 2011-06-08
        • 1970-01-01
        • 1970-01-01
        • 2020-06-10
        相关资源
        最近更新 更多