对于UIScrollView *toScrollView
(这是屏幕的宽度),我想添加一个灰色的底部边框(与iPhone的原生消息应用程序的撰写视图的to-field完全相同).
为了做到这一点,我跟随Cocoa Touch:如何改变UIView的边框颜色和厚度?并使用自定义覆盖顶部边框UINavigationBar
并制作了toScrollView
x坐标-1和宽度322,以便左右边框就在屏幕外.
这看起来很好,但它有点像黑客,我想知道是否有更好的方法来做到这一点.
- (void)viewDidLoad {
[super viewDidLoad];
// Add UINavigationBar *navigationBar at top.
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:@selector(cancelAction)];
UINavigationBar *navigationBar = [[UINavigationBar alloc]
initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
navigationBar.items = [NSArray arrayWithObject:self.navigationItem];
// Add UIScrollView *toScrollView below navigationBar.
UIScrollView *toScrollView = [[UIScrollView alloc]
initWithFrame:CGRectMake(-1.0f, 43.0f, 322.0f, 45.0f)];
toScrollView.backgroundColor = [UIColor whiteColor];
toScrollView.layer.borderColor = [UIColor colorWithWhite:0.8f alpha:1.0f].CGColor;
toScrollView.layer.borderWidth = 1.0f;
[self.view addSubview:toScrollView];
[self.view addSubview:navigationBar]; // covers top of toScrollView …
Run Code Online (Sandbox Code Playgroud) 我有一个类,它是一个子类UIView
.我可以通过实现drawRect
方法或通过实现drawLayer:inContext:
哪个是委托方法在视图中绘制内容CALayer
.
我有两个问题:
如果我实现drawLayer:inContext:
,它被调用(并且drawRect
不是,至少就断点可以告诉),即使我没有CALayer
通过使用以下方式将我的视图指定为委托:
[[self layer] setDelegate:self];
如果我的实例未被定义为图层的委托,那么如何调用委托方法?什么机制可以防止drawRect
被drawLayer:inContext:
调用?
我可以用这种方式为CALayer添加边框:
[webView.layer setBorderColor: [[UIColor colorWithRed:0.6 green:0.7 blue:0.2 alpha:1] CGColor]];
[webView.layer setBorderWidth: 2.75];
Run Code Online (Sandbox Code Playgroud)
但是,是否可以仅在一侧添加边框?我只需要底部的边框.或者我可以用其他属性来达到这个目的,例如框架,边界,面具,......?
谢谢你的帮助!
b控制-V
UIWebView *webView = [[UIWebView alloc] init];
CALayer *webViewLayer = webView.layer;
// now you can do a lot of stuff like borders:
[webViewLayer setBorderColor: [[UIColor greenColor] CGColor]];
[webViewLayer setBorderWidth: 2.75];
Run Code Online (Sandbox Code Playgroud)
请查看CALayer文档:https: //developer.apple.com/documentation/quartzcore/calayer
看看这里:http: //iosdevelopertips.com/cocoa/add-rounded-corners-and-border-to-uiwebview.html
是否可以在UIView之上添加边框,如果是这样,请问怎么样?
一起早上好,
示例:在单元格一中,我的右侧有一个红色文本标签.从它左边我包括一个像灰线的图像.
使用此代码,我可以设置一个完整的绿色边框:
cell.Label.layer.borderWidth = 0.5
cell.Label.layer.borderColor = UIColor.greenColor().CGColor
Run Code Online (Sandbox Code Playgroud)
我可以在此文本标签的左侧仅设置边框吗?我使用swift ios8 - 所以,我需要一个快速的解决方案
我有一个文本字段设置如下:
textField.borderStyle = UITextBorderStyleLine;
textField.layer.borderColor = [[UIColor greenColor] CGColor];
textField.layer.borderWidth= 10.0f;'
Run Code Online (Sandbox Code Playgroud)
但是左侧可能只有一个更大的边框,它是不同的颜色?或者我是否必须使用我想要的颜色和位置来定位drawRect?
我想在UIView周围做一个半透明的边框.这个想法是显示一张图片,但边框覆盖图片的边缘,但仍然可以让你看到边框后面的东西.我希望边框的不同边有不同的边框宽度.在顶部我想有一个80分的边框,在底部我想要一个60分的边框,并在侧面我想要一个10分的边框.我知道使用代码:
UIView.layer.borderColor = [UIColor blueColor].CGcolor;
UIView.layer.borderWidth = 10;
Run Code Online (Sandbox Code Playgroud)
将在UIView内部为您提供宽度为10的均匀边框,但如何为UIView的不同边设置不同的边框宽度?