您的当前位置:首页正文

滚动的button

2024-12-20 来源:伴沃教育

-(void)createWeekBtn

{

_weekAry =@[@"周一",@"周二",@"周三",@"周四",@"周五",@"周六",@"周日"];

for (int i =0; i<_weekAry.count; i++) {

UIButton *titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];

[titleBtn setTitle:[_weekAry objectAtIndex:i] forState:UIControlStateNormal];

[titleBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

titleBtn.frame = CGRectMake(61*i, 0, 60, 60);

titleBtn.layer.masksToBounds =YES;

titleBtn.layer.cornerRadius =titleBtn.frame.size.width/2;

titleBtn.backgroundColor = [UIColor colorWithRed:0 green:220/255.0 blue:180/255.0 alpha:1.0];

titleBtn.tag = i+1;

[titleBtn addTarget:self action:@selector(clickTitleBtn:) forControlEvents:UIControlEventTouchUpInside];

[_myScrollView addSubview:titleBtn];

}

_myScrollView.contentSize = CGSizeMake(60*_weekAry.count+_weekAry.count, 0);

}

- (void)clickTitleBtn:(id)sender

{

UIButton *buttn = (UIButton *)sender;

NSString *titleStr = [_weekAry objectAtIndex:(buttn.tag - 1)];

NSLog(@"%@",titleStr);

}

显示全文