Iphone开发代码片段3

1.给UITableViewController添加ToolBar。

 self.navigationController.toolbarHidden = NO; //默认是隐藏的。

//添加MessageToolBar ,messageToolBar是IBOutlet的一个ToolBar。

 self.toolbarItems =  [[[NSMutableArray alloc] initWithArray:self.messageToolBar.items] autorelease];

 self.navigationController.toolbar.barStyle = self.messageToolBar.barStyle; 

2.后台运行一个方法,如果该方法需要修改UI,为了防止出错,应在主线程里修改UI。

[self performSelectorInBackground:@selector(updateInfo)];

在UpdateInfo里如果要修改UI ,

[self performSelectorOnMainThread:@selector(updateUIMethod) withObject:nil waitUntilDone:NO];

同时注意,后台程序的方法应该放在NSAutoRelease pool里的,如下所示:

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
xxxx
[pool release];

3.在A类里动态的设定B类或者C类的方法。

[self.actionTarget performSelector:self.actionMethod withObject:parameter];

actionTarget   -> id类型的属性。设置B 类或者C类。

actionMethod -> Sel类型的属性。设置具体的方法名

parameter     -> 参数

4.设置Navigation的提示信息和进度条设置

   self.navigationItem.prompt : 提示信息
   self.navigationItem.titleView :存放ProgressBar等其它提示信息的View

   在进度条显示完了后,需要清空显示进度信息:

   self.navigationItem.prompt = nil;
   self.navigationItem.titleView = nil;

5.从资源文件xib里加载View的方法

 NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyView"
                                                         owner:self
                                                       options:nil];
MyView *view = [nib objectAtIndex:0];

6. UIAlterView 修改默认的Frame高度

在其委托里实现这个方法

- (void)willPresentAlertView:(UIAlertView *)alertView 

{

    alertView.frame = CGRectMake(5.f, 1.f, 100.f, 200.f);

}

参考:http://stackoverflow.com/questions/2763713/change-width-of-uialertview-in-ipad

 

 7.获取iphone屏幕大小

CGRect screenBounds = [ [ UIScreen mainScreen ] bounds ];
CGRect screenRect= [ [ UIScreen mainScreen ] applicationframe ]; 

8. 修改TableView的样式,让UITableView显示Windows的背景图片。

    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.opaque = NO;
    self.tableView.backgroundView = nil;

   如果要修改UITableCell的事情backgroundColor需要再 tableView:willDisplayCell:forRowAtIndexPath:里修改。

9.通过图片获取颜色。 

[UIColor colorWithPatternImage:[UIImage imageNamed:@"imageName"]];

修改分割线颜色

 self.tableView.separatorColor = [UIColor blackColor]; 

显示文本的地方设置透明色 

 cell.textLabel.opaque = NO;

 这样整个cell就有立体感。 

10.设置UITableView 的checkmark显示样式

修改cell的 accessoryView 

 cell.accessoryView = UIImageView

11. 修改TableView距离导航缆的高度。 

 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{
    return 10.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectZero] autorelease];;
}

12. 自定义TableViewCell的背景颜色和选择后的颜色。

 方法一:将TableViewCell的backgroundView和SelectBackGroundView修改成指定的View就可以了。

 方法二: 在Interface Builder里设置cell的image和SelectImage属性,但是要记得UItableView修改seperator的属性为None

13 颜色定义。

  美工一般定义好颜色,然后让程序员去填充颜色,美工一般给的是RGB颜色,那么RGB颜色如果换成UIColor

[UIColor colorWithRed:31.0/255 green:204.0/255 blue:39.0/255 alpha:1.0];

Red,Green,Blue只接受0-1的参数,换算方法是除以255。 

14. Xcode 4设置  NSZombieEnabled

 if you click on the scheme drop down bar -> edit scheme -> arguments tab and then add NSZombieEnabled in the Environment Variables column and YES in the value column

15.自动生成多语言化的StringTable

   如果在代码里全部是通过 NSLocalizedString(@"中文", nil)来对应多语言,最后要整理一个list,手动一个一个粘贴太麻烦。

  自动化生成方法:在命令行目录下进入项目根目录:执行 genstrings -a $(find . -name "*.m"),就会自动生成一个文件对应。

  参考网址 http://steelwheels.sourceforge.jp/Documents/genstring.html

http://iphone.longearth.net/2009/05/25/%E3%80%90iphone%E3%80%91localizablestrings%E3%82%92%E8%87%AA%E5%8B%95%E3%81%A7%E4%BD%9C%E3%82%8B-genstrings/ 

16.自定义bond字体 

[UIFont fontWithName:@"Helvetica-Bold" size:16.0] 

17 无边框透明UITableViewCell

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;   

self.tableView.separatorColor = [UIColor clearColor];              

self.tableView.backgroundColor = [UIColor clearColor];   

self.tableView.opaque = NO;   

self.tableView.backgroundView = nil;

--Cell修改--

self.backgroundView = [[[UIView alloc] init] autorelease];       

self.backgroundView.backgroundColor = [UIColor clearColor];       

self.selectedBackgroundView = [[[UIView alloc] init] autorelease];       

self.selectedBackgroundView.backgroundColor = [UIColor clearColor];

18. 隐藏Tabbar

SampleViewController *obj = [[SampleViewController alloc] init];
[obj setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:obj animated:YES];
[obj release];

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值