bView.layer.cornerRadius = 4
CAShapeLayer*borderLayer = [[CAShapeLayeralloc]init]
borderLayer.bounds= bView.bounds
borderLayer.position=CGPointMake(bView.centerX, bView.centerY)
borderLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0,0, 68, 68) cornerRadius:4].CGPath
borderLayer.lineWidth=1
borderLayer.lineDashPattern = @[@6,@4]//前边是虚线的长度,后边是虚线之间空隙的长度
borderLayer.lineDashPhase=0.1
borderLayer.fillColor=UIColor.clearColor.CGColor
borderLayer.strokeColor=BSHexColor(0xA6A8AB).CGColor
[bView.layeraddSublayer:borderLayer]
}
在VIEW的CREAT时将你的对话框(最好是以无模式对话框模式)创建并显示: 如下代码: m_pFaceDlg = new CInterFaceDlg//CInterFaceDlg 为你的对话框类 m_pFaceDlg->Create( IDD_DIALOG_INTERFACE, this )//IDD_DIALOG_INTERFACE为你的对话框ID。我给你写了个简单的UITextView类 你用这个类就会有一个虚线边框.h文件
#import <UIKit/UIKit.h>
@interface MyUITextView : UITextView
@end
.m文件
#import "MyUITextView.h"
@implementation MyUITextView
- (void)drawRect:(CGRect)rect
{
CGContextRef content = UIGraphicsGetCurrentContext()
CGPoint Point[4]
Point[0] = CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect))
Point[1] = CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect))
Point[2] = CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect))
Point[3] = CGPointMake(CGRectGetMaxX(rect), CGRectGetMinY(rect))
CGContextAddLines(content, Point, 4)
CGContextClosePath(content)
[[UIColor grayColor] setStroke]
CGContextSetLineWidth(content, 4)
CGFloat dashArray[] = {4,2}
CGContextSetLineDash(content, 0, dashArray, 2)
CGContextStrokePath(content)
}
@end
其实我就是在边框上面画了一条虚线,如有什么问题,可以继续给我提问
用的时候只需要再ViewController里面这样调用
- (void)viewDidLoad {
[super viewDidLoad]
MyUITextView *text = [[MyUITextView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)]//这个Frame只是我的测试
[self.view addSubview:text]
// Do any additional setup after loading the view, typically from a nib.
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)