iOS alertController之actionsheet样式添加控件(类似自定义actionsheet)

本文介绍了一个使用 Swift 在 iOS 应用中创建 UIAlertController 的具体实例。示例展示了如何根据设备方向调整提示信息,并自定义 UIAlertController 的样式,包括按钮、图片及详细文字说明。

“`python

 NSString*title=UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? @"\n\n\n\n\n\n\n\n\n" : @"\n\n\n\n\n\n\n\n\n\n\n\n" ;

UIAlertController*alert=[UIAlertController alertControllerWithTitle:@"快速兑换" message:title preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction*action=[UIAlertAction actionWithTitle:@"立即兑换" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {}];




 UIAlertAction*action1=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancelhandler:^(UIAlertAction * _Nonnull action) { }];
   [alert addAction:action];
   [alert addAction:action1];

    UIView*img=[[UIView alloc]init];

img.frame=CGRectMake(5,40, SCREEN_WIDTH-30, 220);
//    img.backgroundColor=[UIColor redColor];
[alert.view addSubview:img];
goodsname=@"123456手表";
costCount=@"2000";
totalCount=@"8000";
lastCount=@"6000";
NSString*str=[NSString stringWithFormat:@"立即兑换%@,消费%@积分,您当前账户剩余%@积分,兑换后剩余%@积分,点击下方的【立即兑换】按钮即可兑换。",goodsname,costCount,totalCount,lastCount];
cnvUILabel*label=[[cnvUILabel alloc]initWithFrame:CGRectMake(15, 10, img.frame.size.width-30, [self getHeightWithString:str fontSize:15])];
NSLog(@"---%f",[self getHeightWithString:str fontSize:15]);
label.font=[UIFont systemFontOfSize:15];
[img addSubview:label];
[label cnv_setUILabelText:str andKeyWord1:goodsname andKeyWord2:costCount andKeyWord3:totalCount andKeyWord4:lastCount andKeyword5:@"【立即兑换】"];
[label cnv_setUIlabelTextColor:[UIColor blackColor] andKeyWordColor:[UIColor redColor]];
UIImageView*imagev=[[UIImageView alloc]initWithFrame:CGRectMake(15, 110, 100, 100)];
imagev.image=[UIImage imageNamed:@"u1526"];
StoreImageView*imgg=[[NSBundle mainBundle]loadNibNamed:@"StoreImageView" owner:nil options:nil][0];
[imgg resetFrame:CGRectMake(15, 110, img.frame.size.width-30, 100)];
imgg.storeImage.image=[UIImage imageNamed:@"u1526"];
imgg.storeName.text=goodsname;
imgg.count.text=costCount;
imgg.lastGoods.text=@"剩10件";

//    [imgg drawRect:CGRectMake(15, 110, img.frame.size.width-30, 100)];

[img addSubview:imgg];

[self presentViewController:alert animated:YES completion:^{

}];

“`
示例图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值