@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect

{

// Drawing code

UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:[self cornerRadius]];

[roundedRect addClip];

[[UIColor whiteColor] setFill];

UIRectFill(self.bounds);

[[UIColor blackColor] setStroke];

[roundedRect stroke];

if(self.faceUP){

UIImage *faceImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@", [self rankAsString], self.suit]];

if (faceImage) {

CGRect imageRect = CGRectInset(self.bounds,

self.bounds.size.width * (1.0-self.faceCardScaleFactor),

self.bounds.size.height * (1.0-self.faceCardScaleFactor));

[faceImage drawInRect:imageRect];

} else {

[self drawPips];

}

[self drawCorners];

}else{

[[UIImage imageNamed:@"cardback"] drawInRect:self.bounds];

}

NSLog(@"drawRect");

}

这里设置了倒角,阴影,颜色,还有图片

- (void)pushContextAndRotateUpsideDown

{

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSaveGState(context);

CGContextTranslateCTM(context, self.bounds.size.width, self.bounds.size.height);

CGContextRotateCTM(context, M_PI);

}

- (void)popContext

{

CGContextRestoreGState(UIGraphicsGetCurrentContext());

}

#pragma mark - Corners

- (void)drawCorners

{

NSMutableParagraphStyle *paragraphyStyle = [[NSMutableParagraphStyle alloc] init];

paragraphyStyle.alignment = NSTextAlignmentCenter;

UIFont *cornerFont = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];

cornerFont = [cornerFont fontWithSize:cornerFont.pointSize * [self cornerScaleFactor]];

NSAttributedString *cornerText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@", [self rankAsString], self.suit] attributes:@{ NSFontAttributeName : cornerFont, NSParagraphStyleAttributeName : paragraphyStyle}];

CGRect textBounds;

textBounds.origin = CGPointMake([self cornerOffset], [self cornerOffset]);

textBounds.size = [cornerText size];

[cornerText drawInRect:textBounds];

[self pushContextAndRotateUpsideDown];

[cornerText drawInRect:textBounds];

[self popContext];

}

这里设置了角落上的suit和rank

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

iOS绘制view的更多相关文章

  1. iOS圆角view的Swift实现(利用Core Graphics绘制)

    iOS圆角view的Swift实现(利用Core Graphics绘制) 因为app的列表用用到了圆形图片的头像,所以去探究并思考了一下这个问题.首先这个问题有两个方向的解决方案: 把图片弄成圆形的. ...

  2. iOS Programming View and View Hierarchy 视图和视图等级

    iOS Programming  View and View Hierarchy 视图和视图等级 1.1(1)File → New → Project.. From the iOS section, ...

  3. android绘制view的过程

    1 android绘制view的过程简单描述  简单描述可以解释为:计算大小(measure),布局坐标计算(layout),绘制到屏幕(draw):            下面看看每一步的动作到底是 ...

  4. 【转】Android绘制View的过程研究——计算View的大小

    Android绘制View的过程研究——计算View的大小 转自:http://liujianqiao398.blog.163.com/blog/static/18182725720121023218 ...

  5. iOS 设置View阴影

    iOS 设置View投影 需要设置 颜色 阴影半径 等元素 UIView *shadowView = [[UIView alloc] init]; shadowView.frame = CGRectM ...

  6. iOS Programming View Controllers 视图控制器

    iOS Programming View Controllers  视图控制器  1.1  A view controller is an instance of a subclass of UIVi ...

  7. iOS绘制坐标图,折线图-Swift

    坐标图,经常会在各种各样的App中使用,最常用的一种坐标图就是折线图,根据给定的点绘制出对应的坐标图是最基本的需求.由于本人的项目需要使用折线图,第一反应就是搜索已经存在的解决方案,因为这种需求应该很 ...

  8. iOS 绘制1像素的线

    一.Point Vs Pixel iOS中当我们使用Quartz,UIKit,CoreAnimation等框架时,所有的坐标系统采用Point来衡量.系统在实际渲染到设置时会帮助我们处理Point到P ...

  9. Android 绘制view的小知识点

    [onMeasure] 直接继承view或ViewGroup的自定义控件需要重写onMeasure方法并设置wrap_content时的自身大小,否则在布局中使用wrap_content就相当于mat ...

随机推荐

  1. 关于tuple的只读特性

    a = (1,3,[5,4,1]) a[2][1] = 2 print(a) 结果是:(1,3,[5,2,1]) 可以看到,在这里tuple的内容被修改了. 原因就是tuple的“只读”属性是指tup ...

  2. py2exe 生成带图标的单个文件实例

    随便拉了个学习时用的测试程序来做的实例,原程序如下: #Filename:for.py count=0 for i in range(1,100,2): count+=i else: print 't ...

  3. 【0】python核心编程,第二章

    1.print语句也支持将输入重定向到文件,示例: logfile = open('/tmp/mylog.txt', 'a') print >> logfile, 'Fatal error ...

  4. 愉快的开始 - 零基础入门学习Python000

    愉快的开始 让编程改变世界 Change the world by program 为什么是Python 既然有各种各样的编程语言可以选择,小甲鱼为什么极力鼓励大家来学习Python呢? 跨平台哦亲 ...

  5. C#代码实现,确保windows程序只有一个实例(instance)

    static class Program { /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static vo ...

  6. #1042 - Can't get hostname for your address

    my.ini 或 my.cnf 末尾添加 skip-name-resolve 并重启MySQL服务器 ok!

  7. java List与数组互转

    数组转List:String[] arr = new String[] {"str1", "str2"};List<String> list = A ...

  8. Android Studio参考在线文章

    This article is From :http://www.android-studio.org/index.php/docs/guide Gradle使用手册(一):为什么要用Gradle? ...

  9. Linux系统下定时上传文件至FTP服务器脚本

    环境:Red Hat Enterprise Linux Server release 6.4 需求:需要将Oracle数据库的定时备份上传至FTP服务器 1.干货,用户名:oracle,数据库名称:X ...

  10. poj 1986 Distance Queries(LCA)

    Description Farmer John's cows refused to run in his marathon since he chose a path much too long fo ...