随手记

来源:互联网 发布:女同志交友软件 编辑:程序博客网 时间:2024/04/29 16:13

02-27

今天,写了在navigationbar上添加一个button。

出现问题:在一个页面添加之后,其他所有页面都添加上了,无法去掉。

解决:学习了titleview。

代码如下:

  ///
   UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    titleView.backgroundColor = [UIColor clearColor];
    
    /// 主题类型选择按钮
    UIButton * kindSelectBtn = [LLCreateControls createButtonWithFrame:CGRectMake(240/2 * kWidthScale, 16/2 * kWidthScale, 55/2 , 56/2) Font:16 Image:@"Circle_detailSelectBtnbg" Title:nil Target:self Selector:@selector(selectTopicAction:) BackgroundColor:[UIColor clearColor] TitleColor:[UIColor colorWithRed:100/255.0f green:100/255.0f blue:100/255.0f alpha:1]];
    [titleView addSubview:kindSelectBtn];
    
    topicKindLabel = [LLCreateControls createLabelWithFrame:CGRectMake(100/2 * kWidthScale, 10/2 * kWidthScale, 582/2 , 64/2 * kWidthScale) Font:18 Text:@"最后回复" BackgroundColor:[UIColor clearColor] TextColor:[UIColor colorWithRed:100/255.0f green:100/255.0f blue:100/255.0f alpha:1]];
    [titleView addSubview:topicKindLabel];
    
    self.navigationItem.titleView = titleView;


*********************************************************

02- 28

一。。。。。


实现点击话题标签弹出这些标签,并可以横向滑动。

难点:每个标签标题不一定,长度无法确定,需要根据前一个标签的位置来确定下一个标签的位置。

解决:设置一个静态button,用来保存前一个button。

遇到问题:第一次运行没有问题,退出当前页面再进入时候,就不再显示添加的标签了。

解决:进入该页面需要重新设置那个静态button。

formerButton = [[UIButtonalloc]initWithFrame:CGRectZero];

// 获取上一个button

static UIButton * formerButton;

///

    labelScrollview = [[UIScrollViewalloc]initWithFrame:CGRectMake(0, buttonBgView.bottom +24/2 *kWidthScale,kScreenWidth,42/2 *kWidthScale)];

    labelScrollview.showsHorizontalScrollIndicator =NO;

    labelScrollview.backgroundColor = [UIColorclearColor];

    labelScrollview.contentSize =CGSizeMake(kScreenWidth *2, 42/2 *kWidthScale);

    

    // labelScrollview横向滑动范围

    CGFloat contentWidth =0;

     NSArray * labelTitleArr =@[@"交流",@"病人转诊",@"号召",@"学术交流",@"病人转诊",@"号召"];

    /// 标签button

    for (int i =0; i<6; i++) {

       

        NSUInteger length = [labelTitleArr[i]length];

        NSLog(@"length == %lu,num == %lu",(unsignedlong)length,length/2);

        

        UIButton * labelButton = [LLCreateControlscreateButtonWithFrame:CGRectMake(formerButton.right +22/2 * kWidthScale,0,(74/2 + (length -2) *25/2) *kWidthScale ,42/2)Font:13Image:nilTitle:labelTitleArr[i]Target:selfSelector:@selector(labelBtnAction:)BackgroundColor:[UIColorclearColor]TitleColor:[UIColorcolorWithRed:129/255.0fgreen:129/255.0fblue:129/255.0falpha:1]];

        labelButton.layer.masksToBounds =YES;

        labelButton.layer.cornerRadius =1.0f;

        labelButton.layer.borderWidth =0.5;

        labelButton.layer.borderColor = [UIColorcolorWithRed:129/255.0fgreen:129/255.0fblue:129/255.0falpha:1].CGColor;

        labelButton.tag =200 + i;

        formerButton = labelButton;

        contentWidth += formerButton.width + 22/2 *kWidthScale;

        NSLog(@"contentWidth == %f",contentWidth);

        [labelScrollviewaddSubview:labelButton];

        

    }

    labelScrollview.contentSize = CGSizeMake(contentWidth +22/2 *kWidthScale,42/2 *kWidthScale);

    NSLog(@"labelScrollview.contentSize == %f",labelScrollview.contentSize.width);

二。。。。

红色的部分根据导航栏的标题不同会显示不同高度。

问题:不可以用headerview来做,显示效果不对。

解决:使用tableview协议方法来完成。

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    return[memberKindLabel.textisEqualToString:@"全部"]?96/2 * kWidthScale:68/2 *kWidthScale;

    

}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

 // 添加显示label

}

在导航栏选择按钮的弹出视图的代理方法里刷新tableview。



0 0