题
我想有围绕UITextView
薄灰色边框。我已经通过苹果文件走了,但找不到任何财产那里。请帮助。
解决方案
#import <QuartzCore/QuartzCore.h>
....
// typically inside of the -(void) viewDidLoad method
self.yourUITextView.layer.borderWidth = 5.0f;
self.yourUITextView.layer.borderColor = [[UIColor grayColor] CGColor];
其他提示
添加以下为圆角:
self.yourUITextview.layer.cornerRadius = 8;
下面是我使用的代码,添加在我的名为“tbComments” TextView
控制边框:
self.tbComments.layer.borderColor = [[UIColor grayColor] CGColor];
self.tbComments.layer.borderWidth = 1.0;
self.tbComments.layer.cornerRadius = 8;
这就是它的样子:
易peasy。
我添加UIImageView
作为UITextView
的子视图。这个本机边界相匹配上的UITextField
,包括从顶部至底部的梯度:
textView.backgroundColor = [UIColor clearColor];
UIImageView *borderView = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, textView.frame.size.width, textView.frame.size.height)];
borderView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
UIImage *textFieldImage = [[UIImage imageNamed:@"TextField.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 8, 15, 8)];
borderView.image = textFieldImage;
[textField addSubview: borderView];
[textField sendSubviewToBack: borderView];
这些是我使用PNG图像和一个jpg表示:
作品很大,但颜色应该是一个CGColor
,不UIColor
:
view.layer.borderWidth = 5.0f;
view.layer.borderColor = [[UIColor grayColor] CGColor];
有关夫特编程,使用此
tv_comment.layer.borderWidth = 2
tv_comment.layer.borderColor = UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1).CGColor
这是接近我从原始的UITextField能
func updateBodyTextViewUI() {
let borderColor = UIColor.init(red: 212/255, green: 212/255, blue: 212/255, alpha: 0.5)
self.bodyTextView.layer.borderColor = borderColor.CGColor
self.bodyTextView.layer.borderWidth = 0.8
self.bodyTextView.layer.cornerRadius = 5
}
我相信上面的答案是雨燕的早期版本。我一派位和下面的代码作品夫特4.只要共享它为谁可能受益。
self.textViewName.layer.borderColor = UIColor.lightGray.cgColor
self.textViewName.layer.borderWidth = 1.0;
self.textViewName.layer.cornerRadius = 8;
编码快乐!
的iOS 8和6的Xcode的作为,我现在发现的最佳解决方案是子类的UITextView并标记子类作为IB_DESIGNABLE,这将允许你在故事板查看边界。
部首:
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface BorderTextView : UITextView
@end
实现:
#import "BorderTextView.h"
@implementation BorderTextView
- (void)drawRect:(CGRect)rect
{
self.layer.borderWidth = 1.0;
self.layer.borderColor = [UIColor blackColor].CGColor;
self.layer.cornerRadius = 5.0f;
}
@end
然后,只需拖动出你的UITextView在故事板和它的类设置为BorderTextView
这使它工作(除了此处的答复)的东西被添加borderStyle
属性:
#import <QuartzCore/QuartzCore.h>
..
phoneTextField.layer.borderWidth = 1.0f;
phoneTextField.layer.borderColor = [[UIColor blueColor] CGColor];
phoneTextField.borderStyle = UITextBorderStyleNone;
只需少量添加。如果使边框宽一点,它会与文本的左侧和右侧干涉。为了避免这种情况,我添加下列行:
self.someTextView.textContainerInset = UIEdgeInsetsMake(8.0, 8.0, 8.0, 8.0);
在夫特3,则可以使用以下两行:
myText.layer.borderColor = UIColor.lightGray.cgColor
myText.layer.borderWidth = 1.0
我通过将UIButton
后面完全禁用UITextView
并使UITextView
clearColor的背景色中的故事板解决了这个问题。此作品,而不需要额外的代码或包。
不隶属于 StackOverflow