自定义Cell(以设置界面为例完成封装)(自定义Cell3⃣️)
来源:互联网 发布:软件开发合同 性质 编辑:程序博客网 时间:2024/06/05 10:18
//
// ZZSettingCell.h
// ZZ_APP主流框架
//
// Created by ZZ_Macpro on 15/10/9.
// Copyright (c) 2015年 ZZ_Macpro. All rights reserved.
//
#import "ZZBgCell.h"
@class ZZSettingItem;
@interface ZZSettingCell :ZZBgCell
@property (nonatomic,strong) ZZSettingItem *item;
@property (nonatomic,strong) NSIndexPath *indexPath;
+ (instancetype)cellWithTableView:(UITableView *)tableView;
@end
//
// ZZSettingCell.m
// ZZ_APP主流框架
//
// Created by ZZ_Macpro on 15/10/9.
// Copyright (c) 2015年 ZZ_Macpro. All rights reserved.
//
#import "ZZSettingCell.h"
#import "ZZSettingItem.h"
#import "ZZSettingArrowItem.h"
#import "ZZSettingSwitchItem.h"
#import "ZZSettingCheckItem.h"
#import "ZZSettingLabelItem.h"
#import "ZZBadgeButton.h"
@interface ZZSettingCell()
@property (weak, nonatomic) UITableView *tableView;
/**
* 子标题
*/
@property (weak,nonatomic) UILabel *subtitleLabel;
/**
* 箭头
*/
@property (strong,nonatomic) UIImageView *arrowView;
/**
* 打钩
*/
@property (strong,nonatomic) UIImageView *checkView;
/**
* 开关
*/
@property (strong,nonatomic) UISwitch *switchView;
/**
* 提醒数字
*/
@property (strong,nonatomic) ZZBadgeButton *badgeButton;
@end
@implementation ZZSettingCell
- (ZZBadgeButton *)badgeButton
{
if (_badgeButton ==nil) {
_badgeButton = [[ZZBadgeButtonalloc] init];
}
return_badgeButton;
}
- (UIImageView *)arrowView
{
if (_arrowView ==nil) {
_arrowView = [[UIImageViewalloc] initWithImage:[UIImageimageWithName:@"common_icon_arrow"]];
}
return_arrowView;
}
- (UIImageView *)checkView
{
if (_checkView ==nil) {
_checkView = [[UIImageViewalloc] initWithImage:[UIImageimageWithName:@"common_icon_checkmark"]];
}
return_checkView;
}
- (UISwitch *)switchView
{
if (_switchView ==nil) {
_switchView = [[UISwitchalloc] init];
}
return_switchView;
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
static NSString *ID =@"setting";
ZZSettingCell *cell = [tableViewdequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
cell = [[ZZSettingCellalloc] initWithStyle:UITableViewCellStyleValue1reuseIdentifier:ID];
cell.tableView = tableView;
}
return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [superinitWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// 子标题
UILabel *subtitleLabel = [[UILabelalloc] init];
subtitleLabel.backgroundColor = [UIColorclearColor];
subtitleLabel.textColor = [UIColorlightGrayColor];
subtitleLabel.highlightedTextColor = subtitleLabel.textColor;
subtitleLabel.font = [UIFontsystemFontOfSize:12];
[self.contentViewaddSubview:subtitleLabel];
self.subtitleLabel = subtitleLabel;
// 标题
self.textLabel.backgroundColor = [UIColorclearColor];
self.textLabel.textColor = [UIColorblackColor];
self.textLabel.highlightedTextColor =self.textLabel.textColor;
self.textLabel.font = [UIFontboldSystemFontOfSize:15];
// 最右边的详情文字
self.detailTextLabel.backgroundColor = [UIColorclearColor];
self.detailTextLabel.textColor = [UIColorlightGrayColor];
self.detailTextLabel.highlightedTextColor =self.detailTextLabel.textColor;
self.detailTextLabel.font = [UIFontsystemFontOfSize:13];
self.backgroundColor = [UIColorclearColor];
}
return self;
}
- (void)setItem:(ZZSettingItem *)item
{
_item = item;
// 1.设置数据
[selfsetupData];
// 2.设置右边的控件
[selfsetupRightView];
}
/**
* 设置数据
*/
- (void)setupData
{
// 1.图标
if (self.item.icon) {
self.imageView.image = [UIImageimageWithName:self.item.icon];
}
// 2.标题
self.textLabel.text =self.item.title;
// 3.子标题
if (self.item.subtitle) {
self.subtitleLabel.hidden =NO;
self.subtitleLabel.text =self.item.subtitle;
}else {
self.subtitleLabel.hidden =YES;
}
}
- (void)layoutSubviews
{
[superlayoutSubviews];
if (self.item.subtitle ==nil) return;
// 设置子标题
CGSize subtitleSize = [self.item.subtitlesizeWithFont:self.subtitleLabel.font];
CGFloat subtitleW = subtitleSize.width;
CGFloat subtitleH = subtitleSize.height;
CGFloat subtitleX =CGRectGetMaxX(self.textLabel.frame) +5;
CGFloat subtitleY = (self.contentView.frame.size.height - subtitleH) * 0.5;
self.subtitleLabel.frame =CGRectMake(subtitleX, subtitleY, subtitleW, subtitleH);
}
- (void)setFrame:(CGRect)frame
{
if (iOS7) {
frame.origin.x =ZZTableBorderW;
frame.size.width -=2 * ZZTableBorderW;
}else {
CGFloat x = ZZTableBorderW -9;
frame.origin.x = x;
frame.size.width -=2 * x;
}
[supersetFrame:frame];
}
/**
* 设置右边的控件
*/
- (void)setupRightView
{
if (self.item.badgeValue)
{ // 右边显示数字
self.badgeButton.value =self.item.badgeValue;
self.accessoryView =self.badgeButton;
} elseif ([self.itemisKindOfClass:[ZZSettingLabelItemclass]]) { //右边是文字
self.accessoryView =nil;
ZZSettingLabelItem *labelItem = (ZZSettingLabelItem *)self.item;
self.detailTextLabel.text = labelItem.text;
} elseif ([self.itemisKindOfClass:[ZZSettingSwitchItemclass]]) { //右边是开关
ZZSettingSwitchItem *switchItem = (ZZSettingSwitchItem *)self.item;
self.switchView.on = switchItem.isOn;
self.accessoryView =self.switchView;
} elseif ([self.itemisKindOfClass:[ZZSettingArrowItemclass]]) { //右边是箭头
self.accessoryView =self.arrowView;
} elseif ([self.itemisKindOfClass:[ZZSettingCheckItemclass]]) { //右边是打钩
ZZSettingCheckItem *checkItem = (ZZSettingCheckItem *)self.item;
self.accessoryView = checkItem.isChecked ?self.checkView :nil;
}else { // 右边没有东西
self.accessoryView =nil;
}
}
- (void)setIndexPath:(NSIndexPath *)indexPath
{
_indexPath = indexPath;
int totalRows = [self.tableViewnumberOfRowsInSection:indexPath.section];
NSString *bgName = nil;
NSString *selectedBgName = nil;
if (totalRows == 1) {// 这组就1行
bgName = @"common_card_background";
selectedBgName = @"common_card_background_highlighted";
}else if (indexPath.row ==0) { // 首行
bgName = @"common_card_top_background";
selectedBgName = @"common_card_top_background_highlighted";
}else if (indexPath.row == totalRows -1) { // 尾行
bgName = @"common_card_bottom_background";
selectedBgName = @"common_card_bottom_background_highlighted";
}else { // 中行
bgName = @"common_card_middle_background";
selectedBgName = @"common_card_middle_background_highlighted";
}
self.bg.image = [UIImageresizedImageWithName:bgName];
self.selectedBg.image = [UIImageresizedImageWithName:selectedBgName];
}
@end
- 自定义Cell(以设置界面为例完成封装)(自定义Cell3⃣️)
- 自定义Cell(完成设置界面)并且自定义一个基类控制器(ZZSettingViewController)(自定义Cell4⃣️)
- 诸如设置界面自定义Cell模型item封装(所有界面通用)(自定义Cell1⃣️)
- 自定义Cell模型组Group封装(自定义Cell2⃣️)
- iOS开发UI篇—以微博界面为例使用纯代码自定义cell程序编码全过程
- iOS开发UI篇—以微博界面为例使用纯代码自定义cell程序编码全过程
- 自定义cell 各个空间的frame设置 QQ为例
- iOS开发UI篇—以微博界面为例使用纯代码自定义cell程序编码全过程(一)
- iOS开发UI篇—以微博界面为例使用纯代码自定义cell程序编码全过程(二)
- iOS开发UI篇—以微博界面为例使用纯代码自定义cell程序编码全过程(三·完结)
- iOS开发UI篇—以微博界面为例使用纯代码自定义cell程序编码全过程(三·完结)
- iOS开发UI篇—以微博界面为例使用纯代码自定义cell程序编码全过程(二)
- IOS封装自定义Cell方法
- iOS_14_tableViewController_xib创建和封装自定义cell
- 自定义设置界面
- 自定义Dialog 以加载进度为例
- QT自定义控件,以绘画板为例
- tableView 自定义Cell,仿收藏界面
- sqlalchemy DB表关系研究
- 《软考》——汇编,编译,解释
- 关灯闭灯游戏
- 管理Fragments
- android utils
- 自定义Cell(以设置界面为例完成封装)(自定义Cell3⃣️)
- MyBatis入门(四)---动态SQL
- java多线程
- 20151031考试总结
- Linux中的gps编程
- 创建内部类的实例方法
- 网页性能管理详解
- windows程序托盘图标以及消息提示--示例程序
- 冒泡排序优化