UITextView周围的边框

32

如何在UITextView周围添加边框(类似于UITextField)? 我想允许用户输入多行文本,但不幸的是UITextField不支持多行文本。是否有一种简单的方法来实现这个功能或者我需要在Photoshop中创建一个?

4个回答

74
 #import <QuartzCore/QuartzCore.h> 

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

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

Swift 解决方案。

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

有没有办法恢复默认设置? - lostintranslation
@lostintranslation 试着更改边框宽度和圆角半径的值。 - Krishna Shanbhag

25

Swift解决方案:

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

iOS 8 中不需要导入 QuarzCore


2
解决方案:
contentView.layer.borderWidth = 2.0f;
contentView.layer.borderColor = [[UIColor blueColor] CGColor];
contentView.layer.cornerRadius = 5;

0

这不是发布答案的正确方式,链接随时可能会失效。 - Ümañg ßürmån

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接