自定义控件-中间画线的view
来源:互联网 发布:开源淘宝客系统 编辑:程序博客网 时间:2024/06/06 05:53
直接看效果图:
代码:
#import <UIKit/UIKit.h>
@interface JJCrossedView :UIView
- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title font:(UIFont *)font lineColor:(UIColor *)lineColor;
@end
#import "JJCrossedView.h"
@interface JJCrossedView()
@property(nonatomic,copy)NSString *title;
@property(nonatomic,retain)UIFont *font;
@property(nonatomic,retain)UIColor *lineColor;
@end
@implementation JJCrossedView
- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title font:(UIFont *)font lineColor:(UIColor *)lineColor
{
self = [superinitWithFrame:frame];
if (self) {
self.title = title;
self.font = font;
self.lineColor = lineColor;
}
return self;
}
- (void)drawRect:(CGRect)rect {
//[super drawRect:rect] // 可调用父类方法,显示文本
CGContextRef ref =UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(ref,self.lineColor.CGColor);
//[self.titleColor setStroke];
CGContextSetLineWidth(ref,1.0);
CGContextMoveToPoint(ref,0.0,self.frame.size.height/2.0-2.0);
CGContextAddLineToPoint(ref,self.frame.size.width,self.frame.size.height/2.0+2.0);
CGContextDrawPath(ref,kCGPathStroke);
[self.titledrawInRect:CGRectMake(0.0,0.0,self.frame.size.width,self.frame.size.height)withFont:self.font];
}
使用:
- (void)viewDidLoad {
[superviewDidLoad];
self.view.backgroundColor = [UIColorlightGrayColor];
UIFont *font = [UIFontsystemFontOfSize:14.0];
NSString *str =@"封疆大吏估计";
CGFloat width = [strsizeWithFont:font].width;
CGFloat height = [strsizeWithFont:font].height;
JJCrossedView *view = [[JJCrossedViewalloc]initWithFrame:CGRectMake(20.0,80.0, width, height)
title:str
font:font
lineColor:[UIColorgrayColor]];
view.backgroundColor = [UIColorwhiteColor];
[self.viewaddSubview:view];
}
- 自定义控件-中间画线的view
- 自定义View控件的属性
- 自定义控件View的使用
- 自定义view 中间添加汉字
- android 连线题实现 自定义view 画线
- Android自定义View(一) 画线段
- 自定义UILable (实现在label中间画线)
- 自定义控件,自定义View
- View和自定义控件的绘制流程
- 带自定义属性的view控件
- Android自定义控件View的探讨
- Android自定义控件View的探讨
- Android自定义控件View的探讨
- Android自定义控件View的探讨
- Android自定义控件View的探讨
- Android自定义控件View的探讨
- Android自定义控件View的探讨
- Android自定义控件View的探讨
- ios平台UI自动化策略-UIautomation版(一)[谢绝转载]
- Android Volley完全解析(三),定制自己的Request
- linux下jdk1.7安装
- 数据结构Java实现——④数组——>稀疏矩阵三元组顺序存储
- 组合数取模计算模板
- 自定义控件-中间画线的view
- android的进程和线程
- delphi之多线程编程
- Delphi 枚举
- UI中的手势部分
- Mysql命令
- 检测版本更新
- Android Volley完全解析(四),带你从源码的角度理解Volley
- 在cocos2d-js实现自动绑定cocostudioUI控件与事件(二)