//跳转到 APP Store评论界面
[[UIApplicationsharedApplication]openURL: [NSURLURLWithString:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=1019101915"]];
// 呼叫用户电话
- (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;
}
本文介绍了如何在iOS应用中实现特定功能,包括跳转至App Store评论页面、拨打电话、添加文本到剪贴板及调整UILabel行间距等。提供了具体的Swift代码实现方式。
2191

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



