iOS知识点小集一行代码(持续更新......)


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;




持续更新中......

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值