利用运行时进行控制器之间的跳转
来源:互联网 发布:企业查找软件 编辑:程序博客网 时间:2024/05/17 00:07
利用运行时进行控制器之间的跳转 ##
_actions = @{@”0”:@[@{@”action”:@”pushMygoldcoinVc”},@{@”action”:@”pushMyexChangeVc”},@{@”action”:@”pushMyordesVc”}],
@”1”:@[@{@”action”:@”pushMySellerVc”},@{@”action”:@”pushMymessageVc”}],
@”2”:@[@{@”action”:@”pushSettingVc”}]
};
// 利用cell的indexPath 取出对应的数组中的方法名,利用objc_msgSend 发送消息
NSString *key = [NSString stringWithFormat:@”%zd”,indexPath.section];
//取出对应组对应的字典
NSDictionary *dict = _actions[key][indexPath.row];
if (dict[@”action”]) {
SEL sel = NSSelectorFromString(dict[@”action”]);
if ([self respondsToSelector:sel]) {
objc_msgSend(self, sel);
}
}
//跳转方法
- (void)pushMygoldcoinVc{
[self.navigationController pushViewController:[[ADMygoldcoinController alloc] init] animated:YES];
}
布局扫城视图
int rowNum = 3; 根据行号来计算y值
int colNum = 4; 要保证为4行必须模上一个4 根据列号来计算x值
CGFloat squareWidth = SCREEN_WIDTH / colNum;
CGFloat squareHeight = 44;
UIView headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, squareHeight rowNum)];
for (int i = 0; i < self.titleArr.count; i++) {
int row = i / colNum;
int col = i % colNum;
UILabel squareLab = [[UILabel alloc] initWithFrame:CGRectMake(squareWidth col, squareHeight * row, squareWidth, squareHeight)];
squareLab.tag = i;
squareLab.textAlignment = NSTextAlignmentCenter;
squareLab.font = [UIFont systemFontOfSize:14];
squareLab.text = self.titleArr[i];
[headView addSubview:squareLab];
//只要不是最后一列的话就在label的中心点的位置画一根竖直的线 if (col != colNum - 1) { //y值不确定就设置他的中心点 UIView *verticalView = [[UIView alloc] initWithFrame:CGRectMake(squareWidth * (col + 1), 0, 1, 20)]; verticalView.center = CGPointMake(verticalView.center.x, squareLab.center.y); verticalView.backgroundColor = [UIColor lightGrayColor]; [headView addSubview:verticalView]; } //画水平的线 if (col == 0) { UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, squareHeight * (row + 1), SCREEN_WIDTH, 1)]; lineView.backgroundColor = [UIColor lightGrayColor]; [headView addSubview:lineView]; }}
应用管理用到的九宫格
- (void)viewDidLoad {
[super viewDidLoad];
// 1.设置frame的相关属性
CGFloat appViewW = 100;
CGFloat appViewH = 120;
CGFloat spaceX = 20;
CGFloat spaceY = 30;
CGFloat topMargin = 30;
CGFloat leftMargin = ( self.view.frame.size.width - 3 * appViewW - 2 *spaceX) *0.5;
// 2.创建格子
for (int i = 0; i < self.apps.count; i ++) {
// 2.1创建一个格子视图
UIView *appView = [[UIView alloc]init];
int row = i / 3;//行号 int col = i % 3;//列号 CGFloat appViewX = leftMargin + (appViewW + spaceX)*col; CGFloat appViewY = topMargin + (appViewH + spaceY )*row;
// 2.2设置frame
appView.frame = CGRectMake(appViewX, appViewY, appViewW, appViewH);
// 2.3添加
[self.view addSubview:appView];
// appView.backgroundColor = [UIColor redColor];//设置背景色
NSDictionary *dict = self.apps[i];
// 2.4添加图片
UIImageView *head = [[UIImageView alloc]init];
CGFloat headW = 60;
CGFloat headX = (appViewW - headW) *0.5;
CGFloat headY = 0;
CGFloat headH = 60;
head.image = [UIImage imageNamed:dict[@”icon”]];
head.frame = CGRectMake(headX, headY, headW, headH); [appView addSubview:head];
// head.backgroundColor = [UIColor blueColor];
// 2.5添加label
// 2.5.1 创建一个文本标签
UILabel *nameLabel = [[UILabel alloc]init];
CGFloat nameLabelX = 0;
CGFloat nameLabelY = headY + headH;
CGFloat nameLabelW = appViewW;
CGFloat nameLabelH = 30;
nameLabel.frame = CGRectMake(nameLabelX, nameLabelY, nameLabelW, nameLabelH); [appView addSubview:nameLabel];
// nameLabel.backgroundColor = [UIColor grayColor];
nameLabel.text = dict[@”name”];
// 2.5.2设置文字大小
nameLabel.font = [UIFont systemFontOfSize:13];
// 2.5.3设置文字居中
nameLabel.textAlignment = NSTextAlignmentCenter;
// 2.6添加button
UIButton *downLoadBtn = [[UIButton alloc]init];
CGFloat downLoadBtnX = 10;
CGFloat downLoadBtnY = nameLabelY + nameLabelH + 10;
CGFloat downLoadBtnW = appViewW - downLoadBtnX *2;
CGFloat downLoadBtnH = 30;
downLoadBtn.frame = CGRectMake(downLoadBtnX, downLoadBtnY, downLoadBtnW, downLoadBtnH); [appView addSubview:downLoadBtn];
// downLoadBtn.backgroundColor = [UIColor greenColor];//设置背景色
[downLoadBtn setTitle:@"下载" forState:UIControlStateNormal];//设置文字 [downLoadBtn setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal]; [downLoadBtn setBackgroundImage: [UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateHighlighted];
// downLoadBtn.
// 按钮内部至少有两个控件,一个label,一个imageView,
downLoadBtn.titleLabel.font = [UIFont systemFontOfSize:14];
}
}
2 -
新店开业
去除cell的下划线需要根据tableview的方法
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.bounces = NO;
去除cell的点击效果需要用到cell的方法
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//让label的内容为2行
_conetentLable.numberOfLines = 2;
//图片整个填充
_iconView.contentMode = UIViewContentModeScaleToFill;
自定义cell
+ (instancetype)cellWithTableView:(UITableView*)tableView;
+ (instancetype)cellWithTableView:(UITableView *)tableView {
static NSString *reuseID = @”cell”;
ADNewdateilsCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
if (cell == nil) {
cell = [[ADNewdateilsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
}
return cell;
}
//重写cell初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self setupUI];
}
return self;
}
- (void)setupUI {
UILabel *describeLabel = [UILabel new];
describeLabel.text = @”上地东路”;
describeLabel.font = [UIFont systemFontOfSize:14];
describeLabel.textAlignment = NSTextAlignmentLeft;
[self.contentView addSubview:describeLabel];
self.describeLabel = describeLabel;
UIImageView *iconImageView = [UIImageView new];iconImageView.image = [UIImage imageNamed:@"婚纱详情_07"];[self.contentView addSubview:iconImageView];self.iconImageView = iconImageView;
}
//布局子控件
- (void)layoutSubviews {
[_iconImageView autoAlignAxis:ALAxisHorizontal toSameAxisOfView:_iconImageView.superview];
[_iconImageView autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:_iconImageView.superview withOffset:15];
//设置大小
[_iconImageView autoSetDimensionsToSize:CGSizeMake(16, 16)];
[_describeLabel autoAlignAxis:ALAxisHorizontal toSameAxisOfView:_describeLabel.superview];[_describeLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:_iconImageView withOffset:15];
}
PureLayout 的使用
常见的方法 :
1, 忽略底部设置高度
[nameLabel autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(94, 25, 0, 0) excludingEdge:ALEdgeBottom];
[nameLabel autoSetDimension:ALDimensionHeight toSize:21];
2,设置控件跟控件之间的距离
[texfield autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:texfield.superview withOffset:30];
3,设置控件的大小
[modifyButton autoSetDimensionsToSize:CGSizeMake(12, 15)];
4,设置跟父控件水平垂直居中
[modifyButton autoAlignAxisToSuperviewAxis:ALAxisVertical];
利用PureLayout画cell下面的线 只要在cell中调用这个方法就可以了
// 画线
if ((indexPath.section == 0 && indexPath.row == 2) || (indexPath.section == 1 &&indexPath.row == 1)) {
[self congfigueLineView:cell.contentView edgeInset:UIEdgeInsetsZero excludingEdge:ALEdgeTop];
}else if(indexPath.row == 0){
[self congfigueLineView:cell.contentView edgeInset:UIEdgeInsetsZero excludingEdge:ALEdgeBottom];
}
[self congfigueLineView:cell.contentView edgeInset:UIEdgeInsetsMake(0, 20, 0, 20) excludingEdge:ALEdgeTop];
//画线
- (void)congfigueLineView:(UIView*)contentView edgeInset:(UIEdgeInsets)edgeInset excludingEdge:(ALEdge)edge{
UIView *line = [UIView new];
[contentView addSubview:line];
[line autoPinEdgesToSuperviewEdgesWithInsets:edgeInset excludingEdge:edge];
[line autoSetDimension:ALDimensionHeight toSize:0.5f];
line.backgroundColor = [UIColor lightGrayColor];
}
//让滚动条滚动
- (void)setUpLineViewConstaintX:(CGFloat)scale{
_constraintX.constant = _lineView.width * scale;
//强行更新约束
[self setNeedsLayout];
}
在scrollView代理方法中实现让滚动条滚动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat offset = scrollView.contentOffset.x;
if (offset > SCREEN_WIDTH * 0.5) {
_headerView.sellerButton.selected = YES;
_headerView.userButton.selected = NO;
}else{
_headerView.userButton.selected = YES;
_headerView.sellerButton.selected = NO;
}
[_headerView setUpLineViewConstaintX:offset/SCREEN_WIDTH];
}
- 利用运行时进行控制器之间的跳转
- 多控制器之间的跳转
- 【iOS开发-79】利用Modal方式实现控制器之间的跳转
- 控制器与导航控制器及之间的相互跳转
- Android:Activity之间跳转时停止运行的一种解决办法
- 容器类 视图控制器 页面之间的跳转
- 通过响应者链条完成控制器之间的跳转
- iOS使用自定义URL实现控制器之间的跳转
- iOS使用自定义URL实现控制器之间的跳转
- iOS使用自定义URL实现控制器之间的跳转
- YII contoller控制器之间跳转的方法redirect
- NavigationController 进行指定ViewController之间的跳转
- 适配器中进行Activity之间的跳转
- SpringMVC 控制器中方法之间的跳转(客户端跳转(redirect)和服务器端跳转(forward))
- 点击Cell进行多控制器跳转的简便写法
- iOS开发UIViewCOntroller视图控制器之间跳转切换举例,以及视图控制器生命周期的简单说明
- 控制器的跳转
- 控制器跳转的方式
- android SoundPool播放音效(二)
- 几道很有趣的面试题
- 硬盘物理结构
- JavaEE_Mybatis_SpringMVC_框架整合_lesson3_框架整合+测试用例,数据库到前台的开发流程
- 日历类
- 利用运行时进行控制器之间的跳转
- 封装的tableBar
- Android属性动画完全解析(下),Interpolator和ViewPropertyAnimator的用法
- java获取request中表单参数
- LeetCode解题报告--Combination Sum II
- 继承的实现(代码)
- 51nod1191
- android 实现静态图片文件的手势拉伸缩小
- linux下shell显示-bash-4.1#不显示路径解决方法