博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS Settings 自定义设置通用源码 XIB高效开发
阅读量:7024 次
发布时间:2019-06-28

本文共 5890 字,大约阅读时间需要 19 分钟。

hot3.png

//  SettingCellCell.h

////  SettingCell.h//  YUSettingCell////  Created by yuzhx on 15/5/14.//  Copyright (c) 2015年 BruceYu. All rights reserved.//#import 
#import "YUTextView.h"typedef enum : NSUInteger {    ACCV_None,    ACCV_Accessory,    ACCV_UISwitch} SetInfoAccType;typedef void (^NillBlock_OBJ)(id obj);typedef void (^NillBlock_Nill)(void);@class SettingInfo;@interface SettingCell : UITableViewCell@property (weak, nonatomic) IBOutlet UISwitch *accessorySwitch;@property (weak, nonatomic) IBOutlet UILabel *titleLab;@property (weak, nonatomic) IBOutlet UITextField *describeTexField;@property (weak, nonatomic) IBOutlet YUTextView *describeTexView;@property (weak, nonatomic) IBOutlet UIImageView *IconImg;@property (nonatomic,strong) SettingInfo *setInfo;-(void)setSetInfo:(SettingInfo *)setInfo;@end@interface SettingInfo : NSObject@property (nonatomic,strong) NSString *Title;//主题@property (nonatomic,strong) NSString *Describe;//描述@property (nonatomic,strong) UIImage *IconImg;@property (nonatomic,assign) BOOL DescribeOnlyShow;//描述@property (nonatomic,assign) BOOL isTextField;//默认输入控件为textfield 由于不想影响以前的使用,新增textView@property (nonatomic,assign) BOOL switchOPen;@property (nonatomic,assign) BOOL enableSwitch;@property (nonatomic, assign)  SetInfoAccType accView;@property (nonatomic,copy) NillBlock_OBJ eventBlock;@property (nonatomic,copy) NillBlock_Nill didSelectRowBlock;@property (nonatomic, assign) id handle;@property (nonatomic, assign) SEL SELAction;@end

SettingCell.m

////  SettingCell.m//  YUSettingCell////  Created by yuzhx on 15/5/14.//  Copyright (c) 2015年 BruceYu. All rights reserved.//#import "SettingCell.h"@interface SettingCell()
@end@implementation SettingCell- (void)awakeFromNib{    // Initialization code    self.IconImg.layer.borderWidth = 0.65f;    self.IconImg.layer.cornerRadius = 8.0f;    self.IconImg.layer.borderColor = [[UIColor colorWithWhite:.8 alpha:1.0] CGColor];    self.IconImg.layer.masksToBounds = YES;}- (void)setSelected:(BOOL)selected animated:(BOOL)animated{    [super setSelected:selected animated:animated];        // Configure the view for the selected state}-(void)setSetInfo:(SettingInfo *)setInfo{    _setInfo = setInfo;        self.accessoryType = UITableViewCellAccessoryNone;    self.accessorySwitch.hidden = YES;    self.accessoryView = nil;        if(setInfo.accView == ACCV_Accessory){        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;            }else if(setInfo.accView == ACCV_None){        self.accessoryType = UITableViewCellAccessoryNone;            }else{        self.accessoryView = self.accessorySwitch;        self.accessorySwitch.hidden = NO;        [self.accessorySwitch setOn:setInfo.switchOPen animated:false];        self.accessorySwitch.userInteractionEnabled = setInfo.enableSwitch;    }    //    if (setInfo.SELAction && setInfo.handle){    //        [setInfo.handle performSelector:setInfo.SELAction withObject:nil];    //    }        self.titleLab.text = setInfo.Title;            ///desrc    self.describeTexView.delegate = self;    if (setInfo.handle) {        if (setInfo.isTextField) {            self.describeTexField.delegate = setInfo.handle;        }else{            self.describeTexView.delegate = setInfo.handle;        }    }            self.describeTexView.userInteractionEnabled = NO;    if (setInfo.isTextField) {        self.describeTexField.text = setInfo.Describe;        self.describeTexField.userInteractionEnabled = !setInfo.DescribeOnlyShow;    }else{        self.describeTexView.text = setInfo.Describe;        self.describeTexView.userInteractionEnabled = !setInfo.DescribeOnlyShow;    }            //frame    CGFloat X = 5 + [self LabSize:self.titleLab.font labTex:self.titleLab.text].width +self.titleLab.frame.origin.x;    self.describeTexField.frame = CGRectMake(X,self.describeTexField.frame.origin.y, 290 - X, self.frame.size.height);    self.describeTexField.backgroundColor = [UIColor clearColor];        self.describeTexView.frame = CGRectMake(X, self.describeTexView.frame.origin.y, 290 - X, self.frame.size.height);    self.describeTexView.backgroundColor = [UIColor clearColor];        self.IconImg.hidden = setInfo.IconImg ? NO : YES;    self.IconImg.image = setInfo.IconImg;        CGRect frame = self.titleLab.frame;    frame.origin.x = setInfo.IconImg ? 60 : 15;    self.titleLab.frame = frame;    }#pragma mark - Event Handler -- (IBAction)textfieldEvent:(UITextField*)sender {    if (self.setInfo.eventBlock) {        self.setInfo.eventBlock(((UITextField*)sender).text);    }    self.setInfo.Describe = sender.text;}-(void)textViewDidChange:(UITextView *)textView{    if (self.setInfo.eventBlock) {        self.setInfo.eventBlock(textView.text);    }    self.setInfo.Describe = textView.text;}- (IBAction)switchEvent:(UISwitch*)sender {    if (self.setInfo.eventBlock) {        self.setInfo.eventBlock((UISwitch*)sender);    }    self.setInfo.switchOPen = sender.on;}#pragma mark - Private --(CGSize)LabSize:(UIFont*)Labfont labTex:(NSString*)Text{        NSDictionary * attribute = [NSDictionary dictionaryWithObjectsAndKeys:Labfont,NSFontAttributeName,nil];    CGSize actualsize = [Text boundingRectWithSize:CGSizeMake([[UIScreen mainScreen]applicationFrame].size.width, 10000) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;    actualsize.width += 2;    return actualsize;}@end@implementation SettingInfo- (instancetype)init{    self = [super init];    if (self) {        self.Title = nil;        self.Describe = nil;        self.DescribeOnlyShow = YES;        self.SELAction = nil;        self.handle = nil;        self.accView = ACCV_None;        self.enableSwitch = YES;        self.isTextField = YES;    }    return self;}@end

效果图如下

235507_8QlU_868062.png

源码下载地址:

转载于:https://my.oschina.net/u/868062/blog/349671

你可能感兴趣的文章
IIS连接数据库:数据库连接出错,请检查连接字串
查看>>
centos7救援模式--rescue模式
查看>>
C++ 输出到文本文件
查看>>
sql Lloader
查看>>
使用python学习【机器学习】需要安装的库~
查看>>
第一次作业+105032014098
查看>>
Codeforces 832B: Petya and Exam
查看>>
axios链接带参数_VUE升级(全面解析vuecil3/vuecil4的vue.config.js等常用配置,配置axios)...
查看>>
vue warning如何去掉_详解vue组件三大核心概念
查看>>
qt mysql md5加密_Qt 给密码进行MD5加密
查看>>
用java swing做连连看_java基于swing实现的连连看代码
查看>>
java关键字定义字符变量_Java 关键字和标识符
查看>>
java并发编程核心方法与框架_Java并发编程核心方法与框架-CompletionService的使用...
查看>>
java开源api网关_常用的几个开源 API网关管理系统
查看>>
java 数据结构 快速入门_Java 数据结构
查看>>
mysql 事务 隔离级别_MySQL中四种事务隔离级别详解
查看>>
leetcode 459 java_【leetcode刷题】[简单]459. 重复的子字符串(repeated substring pattern)-java...
查看>>
oracle12 se1和se2,小屏党的最终执念,12Mini和SE2,到底谁更值得入手?
查看>>
include top.php,Php 安全错误 Top 7
查看>>
oracle itl槽,事务槽(ITL)
查看>>