- 浏览: 340336 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
leslie89757:
[img][img][img][img][img][img][ ...
CocoaPods 安装使用 -
hanmeizhi:
very useful to me. Thanks
Dismissing MPMoviePlayerViewController the right way -
luzj:
这个考虑不周全, 在iOS5的键盘高度就不是这个值了,这样写死 ...
UITextView: move view when keyboard appears -
xjg19870111:
不错。
objective-c NSString 常用操作 -
juedui0769:
现在已经不行了!
android源码下载
start open xcode and create a new project, chose the template as “Navigation Based” and name it as “CustomCellTestProject”. What template you chose does not matter, refer my previous posts to find how you can start working on any template.
First thing we will do is create a customCell. Right click on Classes and add a new UITableViewCell subclass. Name it as “CustomCell”. Now open CustomCell.h and add the following code:
We create the three elements and added them to the contentView of our cell.
synthesize all the three elements in CustomCell.m as we are going to access these elements from other classes.
Here we have simply added a primary label to display the primary text, a secondary label and an imageView. These elements will be created and added into the content view of our custom cell. So open CustomCell.m and add the following code
Now, we have already added the UI elements into our cell but you must have noticed, we have not yet defined how these elements will appear inside cell. Go ahead and add the following code for that:
You can do anything in this method to define the lay out of cell. I have simply assigned frames to all the elements.
You can also find a method in CustomCell.m
This method can be used to define how your cell should react when it is selected. You can describe what should be the highlight color or may be you want to flash one of the labels anything of your choice. I am leaving this method as it is.
We are done with creating our custom cell and now we have to use it. Open RootViewController.m and import CustomCell.h at the top.
I am going to create 5 cells here, you can just use your own logic of specifying number of cells and data. So change the following method to look like this:
Now we are going to use our custom cell. If you look at the cellForRow method, you will find that a UItableViewCell has been created and re used. Now all we have to do is to replace this cell with our new cell. Change the code inside this method to look like this:
I have added some dummy data. You can use your data source to provide data for primaryLabel and secondaryLabel. Please note that I have used three images here. You can use any image of your choice. All you need to to do is copy the images and paste it into your project root folder (which in this case is CustomCellTestProject folder). After pasting the files, in xcode right click on Resources (or any group), select Add >> ExistingFiles and then select all the images you want to add in you project. Once added you can simply use them by their names.
Thats it, go ahead and run the project. You will find something wrong when you compare you simulator screen with mine. If you noticed in the CustomCell.m, I have given some frames to the UI elements. You need to make sure that the height of your cell large enough to accomodate all the elements. So add this following code and you fixed the issue:
First thing we will do is create a customCell. Right click on Classes and add a new UITableViewCell subclass. Name it as “CustomCell”. Now open CustomCell.h and add the following code:
#import @interface CustomCell : UITableViewCell { UILabel *primaryLabel; UILabel *secondaryLabel; UIImageView *myImageView; } @property(nonatomic,retain)UILabel *primaryLabel; @property(nonatomic,retain)UILabel *secondaryLabel; @property(nonatomic,retain)UIImageView *myImageView; @end
We create the three elements and added them to the contentView of our cell.
synthesize all the three elements in CustomCell.m as we are going to access these elements from other classes.
@synthesize primaryLabel,secondaryLabel,myImageView;
Here we have simply added a primary label to display the primary text, a secondary label and an imageView. These elements will be created and added into the content view of our custom cell. So open CustomCell.m and add the following code
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) { // Initialization code primaryLabel = [[UILabel alloc]init]; primaryLabel.textAlignment = UITextAlignmentLeft; primaryLabel.font = [UIFont systemFontOfSize:14]; secondaryLabel = [[UILabel alloc]init]; secondaryLabel.textAlignment = UITextAlignmentLeft; secondaryLabel.font = [UIFont systemFontOfSize:8]; myImageView = [[UIImageView alloc]init]; [self.contentView addSubview:primaryLabel]; [self.contentView addSubview:secondaryLabel]; [self.contentView addSubview:myImageView]; } return self; }
Now, we have already added the UI elements into our cell but you must have noticed, we have not yet defined how these elements will appear inside cell. Go ahead and add the following code for that:
- (void)layoutSubviews { [super layoutSubviews]; CGRect contentRect = self.contentView.bounds; CGFloat boundsX = contentRect.origin.x; CGRect frame; frame= CGRectMake(boundsX+10 ,0, 50, 50); myImageView.frame = frame; frame= CGRectMake(boundsX+70 ,5, 200, 25); primaryLabel.frame = frame; frame= CGRectMake(boundsX+70 ,30, 100, 15); secondaryLabel.frame = frame; }
You can do anything in this method to define the lay out of cell. I have simply assigned frames to all the elements.
You can also find a method in CustomCell.m
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state }
This method can be used to define how your cell should react when it is selected. You can describe what should be the highlight color or may be you want to flash one of the labels anything of your choice. I am leaving this method as it is.
We are done with creating our custom cell and now we have to use it. Open RootViewController.m and import CustomCell.h at the top.
#import “CustomCell.h”
I am going to create 5 cells here, you can just use your own logic of specifying number of cells and data. So change the following method to look like this:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 5; }
Now we are going to use our custom cell. If you look at the cellForRow method, you will find that a UItableViewCell has been created and re used. Now all we have to do is to replace this cell with our new cell. Change the code inside this method to look like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @”Cell”; CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; } // Set up the cell… switch (indexPath.row) { case 0: cell.primaryLabel.text = @"Meeting on iPhone Development"; cell.secondaryLabel.text = @"Sat 10:30"; cell.myImageView.image = [UIImage imageNamed:@"meeting_color.png"]; break; case 1: cell.primaryLabel.text = @"Call With Client"; cell.secondaryLabel.text = @"Planned"; cell.myImageView.image = [UIImage imageNamed:@"call_color.png"]; break; case 2: cell.primaryLabel.text = @"Appointment with Joey"; cell.secondaryLabel.text = @"2 Hours"; cell.myImageView.image = [UIImage imageNamed:@"calendar_color.png"]; break; case 3: cell.primaryLabel.text = @"Call With Client"; cell.secondaryLabel.text = @"Planned"; cell.myImageView.image = [UIImage imageNamed:@"call_color.png"]; break; case 4: cell.primaryLabel.text = @"Appointment with Joey"; cell.secondaryLabel.text = @"2 Hours"; cell.myImageView.image = [UIImage imageNamed:@"calendar_color.png"]; break; default: break; } return cell; }
I have added some dummy data. You can use your data source to provide data for primaryLabel and secondaryLabel. Please note that I have used three images here. You can use any image of your choice. All you need to to do is copy the images and paste it into your project root folder (which in this case is CustomCellTestProject folder). After pasting the files, in xcode right click on Resources (or any group), select Add >> ExistingFiles and then select all the images you want to add in you project. Once added you can simply use them by their names.
Thats it, go ahead and run the project. You will find something wrong when you compare you simulator screen with mine. If you noticed in the CustomCell.m, I have given some frames to the UI elements. You need to make sure that the height of your cell large enough to accomodate all the elements. So add this following code and you fixed the issue:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 50; }
发表评论
-
IOS7.1 企业应用 证书无效 已解决
2014-05-10 10:53 774http://www.cocoachina.com/bbs/r ... -
xCode Find&Replace快捷键
2013-10-28 10:44 907As for Find & Replace, they ... -
iOS整合zxing需要注意的地方
2013-08-02 23:34 2106Well, at last I got it working. ... -
iOS 自定义Tabbar
2013-07-30 22:55 1191http://www.appcoda.com/ios-prog ... -
Apple Push Notification Service总结
2013-07-29 22:39 1115苹果推送通知服务使用总结 1. 在 Mac 上从 KeyCha ... -
iOS 消息推送原理及实现
2013-07-12 13:40 856链接: http://www.dapps.net/dev/ ... -
GIMP IMAGE MAP
2013-05-29 16:13 854使用GIMP 制作 IMAGE MAP 1. 选择图片,用G ... -
INSPIRATION
2013-05-27 18:21 813http://www.patternsofdesign.co. ... -
iOS 自定义控件系列
2013-05-27 17:09 1481iOS自定义控件 自定义UITableViewCell ht ... -
CocoaPods 使用教程
2013-05-27 14:49 768http://mobile.tutsplus.com/tuto ... -
IOS 开发之设置UIButton的title
2013-05-11 22:03 1207btn.frame = CGRectMake(x, y, wi ... -
REActivityViewController 使用 备忘
2013-04-22 21:38 1059REActivityViewController Out o ... -
VPS配置二级域名
2013-04-18 23:08 7881. 域名解析商配置泛解析 主机记录 * 记录类型 A 2. ... -
ios 开发NewsStand指南
2013-04-13 21:44 1324http://www.viggiosoft.com/blog/ ... -
Python Django mod_wsgi Windows 部署过程 备忘
2013-04-10 18:28 1587部署环境:Windows2003Server 1. 安装Ap ... -
网站迁移 备忘
2013-04-10 14:58 7511. 备份数据库。。。导出的格式和编码要注意 2. 完全导出网 ... -
Windows下命令行查看端口占用
2013-04-09 23:42 723在windows命令行窗口下执行: C:\>netst ... -
带预览功能又可分页的UIScrollView
2013-04-05 12:56 823带预览功能又可分页的UIScrollView http:// ... -
25 iOS App 性能优化
2013-04-05 10:51 695http://www.raywenderlich.com/ ... -
UIScrollView滚动, 中间显示整图, 前后露出部分图
2013-04-04 00:12 1200UIScrollView *scrollowView = [[ ...
相关推荐
Details on a custom function that retrieves the formula of a cell, which can be useful for analyzing or manipulating formulas programmatically. **Workbooks (Page 23)** Various workbook-related ...
Chapter 11: Creating a Drupal Block Programmatically and Basic MySQL Usage Chapter 12: Theming Your Site Part 1: Theme Functions and a Twig Primer Chapter 13: Theming Your Site Part 2: Creating a ...
Creating a Windows Form Application 574 Control Class 579 Size and Location 580 Appearance 580 User Interaction 580 Windows Functionality 582 Miscellaneous Functionality 582 Class Hierarchy 582 ...
Programmatically Creating Data Sources Other Interesting Settings Your Environment Data Definition Language Commands CDatabase and CDaoDatabase Opening DAO Databases Connection Settings SQL ...
PDFsharp is a .NET library for creating and modifying Adobe PDF documents programmatically from any .NET language like C# or VB.NET. PDFsharp defines classes for the objects found in PDF files, so you...
- **The First Class**: This involves defining a simple Java class that will be mapped to a database table. - **The Mapping File**: Here, you learn how to create an XML file that describes the mapping ...
能够将整个project 中form 的 localizable 设置为true,也可以批量更改form 的属性。 下载完毕之后,将文件解压到E盘,然后,在visual studio 2010 的 tools 下面选择“options” ->“Add-in/Macros Security" 点击...
- **Creating Custom PowerShell Snap-Ins**: Snap-ins provide a way to extend the PowerShell environment with additional cmdlets and functionality. This section explains how to create a custom snap-in ...
Servlets和JSP核心技术 卷2 内容还是很详细的,看过卷1的人可以继续用这本书深造,呵呵 目录: Chapter 1....Section 1.1....Section 1.2....Section 1.3.... Example: Creating a Web Application WAR File Index
没办法,文件超出上传20M限制 Servlets和JSP核心技术 卷2 内容还是很详细的,看过卷1的人可以继续用这本书深造,呵呵 目录: Chapter 1.... Example: Creating a Web Application WAR File Index
Q373762 - Ribbon Form - Restoring down a minimized application incorrectly resizes the Windows Aero Glass frame after the Ribbon form was programmatically hidden when minimizing the application ...
Q373762 - Ribbon Form - Restoring down a minimized application incorrectly resizes the Windows Aero Glass frame after the Ribbon form was programmatically hidden when minimizing the application ...
(23KB)<END><br>16,custlist.zip CUSTLIST shows how to use custom draw in a list view control. (23KB)<END><br>17,div.zip This sample shows how floating-point exceptions may be captured and ...
Library for creating process loading button with stripes Download Add to gradle root: Download: AndroidX support: Screenshots How to use? Adjust the xml view More examples.: Adjust programmatically ...
A table lists the standard options that can be applied to all types of button widgets, such as text, image, and command bindings. **4.3 Table of Options for Button-Type Widgets** This table provides...