iOS之自定义UIAlertViewController (UIPickerView, 自定义View)

本文介绍了如何在iOS8及以上版本中将UIPickerView与UIAlertViewController结合,提供了一个名为LCAlertViewController的开源库,该库还支持添加自定义的UIView(如UIImageView, UILabel)。虽然自定义View的坐标需要精细调整,但可以实现理想效果。此外,LCAlertViewController的宽度会根据系统样式和动画效果自动适配。" 132683094,19694775,Python编程:利用normalize参数处理日期信息,"['Python', '开发语言', '日期处理']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一,说明


支持iOS8及以上,LCAlertViewController将 UIPickerView和UIAlertViewController结合, 并且添加自定义的View
GITHub地址:
https://github.com/LuochuanAD/LCAlertViewController
在这里插入图片描述


二,UIPickerView 与UIAlertViewController结合


typedef void(^PickerViewDidSelectedBlcok) (NSInteger component, NSInteger row);
@property (nonatomic, strong) UIPickerView * pickerView;
/**
 *  UIPickerView 与 UIAlertViewController 结合
 *
 *  @param title alertViewController's title
 *
 *  @param array pickerView's dataSources
 *
 *  @param style alertViewController's style
 */
+ (LCAlertViewController *)LC_alertControllerWithTitle:(NSString *)title dataArray:(NSArray *)array preferredStyle:(LCAlertViewControllerStyle)style;

- (void)LC_addAction:(UIAlertAction *)action withPickerBlock:(PickerViewDidSelectedBlcok)block;



***三,UIView (:UIImageView,UILable…)与UIAlertViewController结合 ***



自定义view的加载 是计算了 添加空格的多少. 所以坐标不准确. 但在实际项目中,只要仔细调整一下位置, 都是可以呈现出完美效果的.


typedef void(^CustomViewCallBackBlcok) (NSString * callBackString);
typedef void(^FixedWidthBlcok) (CGFloat customViewWidth);
@property (nonatomic, copy) CustomViewCallBackBlcok callBackBlock;
/**
 *  自定义View 警告 此处的view的坐标高度是 用空格的多少代替.  坐标在实际项目中需要仔细调整
 *  CustomViewCallBackBlcok 的作用 看实际的需求
 *
 *  @param title alertViewController's title
 *
 *  @param view  customView
 *
 *  @param style alertViewController's style
 *
 *  @param block 返回的是系统固定 alertViewController的宽度
 */
+ (LCAlertViewController *)LC_alertControllerWithTitle:(NSString *)title customView:(UIView *)view preferredStyle:(LCAlertViewControllerStyle)style customWidth:(FixedWidthBlcok)block;

- (void)LC_addAction:(UIAlertAction *)action withCustomBlock:(CustomViewCallBackBlcok)block;


***注意: ***



由于使用的是系统的样式与动画效果, 那么LCAlertViewController的宽度和系统的保持相等
LCAlertViewControllerStyleAlert :
宽度为 270;

LCAlertViewControllerStyleActionSheet:
iOS12.x版本 宽度为self.view.frame.size.width-16
iOS12.0以下 宽度为self.view.frame.size.width-20


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值