1. 打电话
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",telStr]]];2. 复制字符串到剪贴板
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string =self.label.text;3. 父子试图的透明度互不干扰
fatherView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.5];4. 设置坐标原点从导航条下方开始
self.navigationController.navigationBar.translucent = NO;
5. 聊天框的图片拉伸:
// 这是UIImage的一个方法
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;
// 可拉伸的范围都是距离leftCapWidth后的1竖排像素,和距离topCapHeight后的1横排像素。6. 按钮取消点击效果
btton.adjustsImageWhenHighlighted = NO;7. 在UITableView显示数据, 当数据源很少的时候, 不显示多余的默认空cell:
// 在定义UITableView的时候, 设置footView
UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
_tableView.tableFooterView = v;
8. UITableView cell分割线的间距:
// 设置cell分割线的左右边距
_tableView.separatorInset = UIEdgeInsetsMake(0, 40, 0, 40); // 间距 上, 左, 下, 右
// 系统tableView默认分割线延伸至全屏
// S1:重写下面的代理方法
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
// S2:并在viewDidLoad方法中添加:
if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[_tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[_tableView setLayoutMargins:UIEdgeInsetsZero];
}
9. 播放提示音
NSURL *tapSound = [[NSBundle mainBundle] URLForResource:@"ScanFinished" withExtension:@"caf"];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:tapSound error:nil];
[player prepareToPlay];
[player play];
10. 设置应用图标左上角的badge number
[UIApplication sharedApplication].applicationIconBadgeNumber = 5;
本文汇总了iOS开发中常用的技巧,包括拨打电话、复制文本到剪贴板、调整视图透明度、设置坐标原点、图片拉伸、取消按钮点击效果等。此外还介绍了如何在UITableView中优化显示效果、播放提示音及设置应用图标badge number的方法。
1971

被折叠的 条评论
为什么被折叠?



