绘制 UITableViewCell
来源:互联网 发布:广电网络 股票 编辑:程序博客网 时间:2024/06/06 01:14
#import <UIKit/UIKit.h>// to use: subclass ABTableViewCell and implement -drawContentView:@interface ABTableViewCell : UITableViewCell{UIView *contentView;}- (void)drawContentView:(CGRect)r;// subclasses should implement@end
#import "ABTableViewCell.h"@interface ABTableViewCellView : UIView@end@implementation ABTableViewCellView- (void)drawRect:(CGRect)r{[(ABTableViewCell *)[selfsuperview] drawContentView:r];}@end@implementation ABTableViewCell- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{if ((self = [superinitWithStyle:style reuseIdentifier:reuseIdentifier])) {contentView = [[ABTableViewCellViewalloc]initWithFrame:CGRectZero];contentView.opaque =YES;[selfaddSubview:contentView];}return self;}- (void)setFrame:(CGRect)f{[supersetFrame:f];CGRect b = [selfbounds];b.size.height -=1; // leave room for the seperator line[contentView setFrame:b];}- (void)setNeedsDisplay{[supersetNeedsDisplay];[contentViewsetNeedsDisplay];}- (void)drawContentView:(CGRect)r{// subclasses should implement this}@end
#import <UIKit/UIKit.h>#import "ABTableViewCell.h"@interface CustomDrawnCell : ABTableViewCell { NSString *_title; NSString *_subTitle; NSString *_timeTitle; UIImage *_thumbnail;}- (void)setTitle:(NSString*) title subTitle:(NSString*) subTitle time:(NSString*) time thumbnail:(UIImage *)aThumbnail;@end
#import "CustomDrawnCell.h"@implementation CustomDrawnCellstatic UIFont *titleFont = nil;static UIFont *subTitleFont = nil;static UIFont *timeTitleFont = nil;- (void)setTitle:(NSString*) aTitle subTitle:(NSString*) aSubTitle time:(NSString*) aTimeTitle thumbnail:(UIImage *)aThumbnail{ if (_title != aTitle) { _title = aTitle; } if (_subTitle != aSubTitle) { _subTitle = aSubTitle; } if (_timeTitle != aTimeTitle) { _timeTitle = aTimeTitle; } if (_thumbnail != aThumbnail) { _thumbnail = aThumbnail; } [self setNeedsDisplay];}+(void) initialize{ titleFont = [UIFont systemFontOfSize:17]; subTitleFont = [UIFont systemFontOfSize:13]; timeTitleFont = [UIFont systemFontOfSize:10];}+(void) dealloc{ [super dealloc];}-(void) drawContentView:(CGRect)r{ static UIColor *titleColor; titleColor = [UIColor darkTextColor]; static UIColor *subTitleColor; subTitleColor = [UIColor darkGrayColor]; static UIColor *timeTitleColor; timeTitleColor = [UIColor colorWithRed:0 green:0 blue:255 alpha:0.7]; CGContextRef context = UIGraphicsGetCurrentContext(); if(self.highlighted || self.selected){CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);CGContextFillRect(context, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height));CGContextSetFillColorWithColor(context, titleColor.CGColor);}else{CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);CGContextFillRect(context, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height));CGContextSetFillColorWithColor(context, titleColor.CGColor);} [titleColor set]; [_thumbnail drawInRect:CGRectMake(12, 4, 35, 35)]; [_title drawAtPoint:CGPointMake(54, 3) forWidth:200 withFont:titleFont fontSize:17 lineBreakMode:UILineBreakModeTailTruncation baselineAdjustment:UIBaselineAdjustmentAlignCenters]; [subTitleColor set]; [_subTitle drawAtPoint:CGPointMake(54, 23) forWidth:200 withFont:subTitleFont fontSize:13 lineBreakMode:UILineBreakModeTailTruncation baselineAdjustment:UIBaselineAdjustmentAlignCenters]; [timeTitleColor set]; [_timeTitle drawAtPoint:CGPointMake(262, 3) forWidth:62 withFont:timeTitleFont fontSize:10 lineBreakMode:UILineBreakModeTailTruncation baselineAdjustment:UIBaselineAdjustmentAlignCenters]; }@end
0 0
- 绘制 UITableViewCell
- * 重新绘制UITableViewCell线的方法
- iOS开发给UITableViewCell绘制分割线
- IOS之Quartz2D绘图5.绘制UITableViewCell渐变背景
- UITableViewCell
- UITableViewCell
- UITableViewCell
- UITableViewCell
- UITableViewCell
- UITableViewCell
- UITableViewCell
- uitableviewcell
- UITableviewcell
- UITableViewCell
- UITableViewCell
- UITableViewCell
- UITableViewCell
- UITableViewCell
- 黑马程序员-IO流 03
- Sql server left join,right join和inner join的比较
- 虚函数
- cocos2d-x - loading加载动画
- 最长连续片段
- 绘制 UITableViewCell
- java之Class
- 五个男人30年在同一位置拍摄相同合影,岁月不饶人啊
- 看不到的利益是商机
- 学习笔记 SimpleDateFormat
- CentOS 5.8 中源码安装apache2.4.7和php5.4.23
- Pat(Advanced Level)Practice--1004(Counting Leaves)
- vc自定义消息的发送与接收的方法实现
- 黑马程序员-IO流04