IOS开发 小技能

本文介绍了如何在iOS应用中实现特定功能,包括跳转至App Store评论页面、拨打电话、添加文本到剪贴板及调整UILabel行间距等。提供了具体的Swift代码实现方式。

//跳转到 APP Store评论界面

 [[UIApplicationsharedApplication]openURL: [NSURLURLWithString:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=1019101915"]];


//id=1019101915 这个是APP的id

// 呼叫用户电话

- (void)buttonPhoneAndName:(UIButton *)button{

    NSLog(@"电话");

    UIWebView*callWebview =[[UIWebViewalloc]init];

    NSString *str =[NSStringstringWithFormat:@"tel:%@",_tel];

    NSURL *telURL =[NSURLURLWithString:str];//貌似tel://或者 tel:都行

    [callWebview loadRequest:[NSURLRequestrequestWithURL:telURL]];

    //记得添加到view

    [self.viewaddSubview:callWebview];

}


//把文字添加到剪贴板

 UIPasteboard *pasteboard = [UIPasteboardgeneralPasteboard];

 pasteboard.string = @"剪贴板";


//拼接后的字符串更改字体颜色大小

                NSMutableAttributedString *attributedString = [[NSMutableAttributedStringalloc]initWithString:[NSStringstringWithFormat:@"%@: %@",[[secondComobjectAtIndex:i]objectForKey:@"nickname"],[[secondComobjectAtIndex:i]objectForKey:@"content"]]];

                NSDictionary *attris = @{

                                         NSForegroundColorAttributeName:[UIColorcolorWithRed:0.1green:0.1blue:0.8 alpha:0.6],

                                         NSBackgroundColorAttributeName:[UIColorclearColor],

                                         NSFontAttributeName:[UIFontsystemFontOfSize:13.0f]

                                         };


                [attributedString setAttributes:attris range:NSMakeRange(0, 10)];


//修改UILabel的行间距

  //创建NSMutableAttributedString实例,并将text传入

    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:model.description1];

    //创建NSMutableParagraphStyle实例

    NSMutableParagraphStyle *style = [[NSMutableParagraphStylealloc]init];

    //设置行距

    [style setLineSpacing:0.5f];

    //判断内容长度是否大于Label内容宽度,如果不大于,则设置内容宽度为行宽(内容如果小于行宽,Label长度太短,如果Label有背景颜色,将影响布局效果)

    NSInteger leng = self.view.frame.size.width - (companyLabel.frame.origin.x * 2);

    if (attStr.length < self.view.frame.size.width - (companyLabel.frame.origin.x * 2)) {

        leng = attStr.length;

    }

    //根据给定长度与style设置attStr式样

    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, leng)];

    //Label获取attStr式样

    commentLabel.attributedText = attStr;


           

//计算一个控件在当前屏幕的位置

    CGRect frame = [[headButton superview] convertRect:headButton.frame toView:self.view];



#pragma mark - 计算字符串的长度

-(CGFloat)newWidth:(NSString *)str systemFontOfSize:(CGFloat)size{

    CGFloat newWidth = [str boundingRectWithSize:CGSizeMake(MAXFLOAT, 28)

                                         options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading

                                      attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:size]}

                                         context:nil].size.width;

    return newWidth;

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值