@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. MAC下用OPENSSL生成公钥和私钥

    MAC OS自带了OpenSSL,所以不用去编译那一坨跟SHIT一样的源码.直接在命令行里使用OPENSSL就可以. 打开命令行工具,然后输入 openssl打开openssl,接着只要三句命令就可以 ...

  2. ubuntu 新建zend framework 项目

    1. sudo apt-get install zend-framework /usr/share/php/libzend-framework-php 2. 配置include_path /etc/p ...

  3. 理解Python中的装饰器

    文章先由stackoverflow上面的一个问题引起吧,如果使用如下的代码: @makebold @makeitalic def say(): return "Hello" 打印出 ...

  4. Font Rending 的 Hint 机制对排版的影响

    Font Rending 的 Hint 机制对排版的影响[转] 在设计一种 Font 时,设计者使用的是一个抽象的单位,叫做 EM,来源于大写 M 的宽度(通常英文字体中大写 M 的宽度最大).EM ...

  5. android学习精要

    第1章 初识android1.1 android平台概述1.2 android平台体系1.2.1 linux kernel内核层1.2.2 系统运行库libraries和android runtime ...

  6. Cocos2d-x 2.1.5 简单动画

    Cocos2d新版本函数更改了一些. 下面的代码可以产生一个简单动画. //第一步:生成动画需要的数据 CCTexture2D *texture=CCTextureCache::sharedTextu ...

  7. setTimeout()使用

    Basic setTimeout() Example setTimeout(function() {       // Do something after 5 seconds }, ); Tip:  ...

  8. UESTC_Big Brother 2015 UESTC Training for Graph Theory<Problem G>

    G - Big Brother Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) ...

  9. UESTC_王之迷宫 2015 UESTC Training for Search Algorithm & String<Problem A>

    A - 王之迷宫 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  ...

  10. 【转】morgan stanley 电面面经新鲜出炉

    楼楼早上上午大概11点接到的电话,一个声音炒鸡好听的GG,说他是来自morgan stanley的,想和我约一下店面时间.我一听,真是戳不及防,掐指一算,online的IKE测试已经过去20几天了吧, ...