スクリーンショットでわかるように、UIスクロールビューで複数のボタンを動的に作成しました。すべてのボタンは実際に日付アクションを保持し、その日付の特定のイベントがテーブルにロードされます。 UIスクロールビューは、コード内のグローバル要素であり、コントローラ内のどのメソッドからもアクセスできます。objective c uiscrollviewで動的に作成されたボタンの背景色にアクセスして変更する方法
今私が望んでいたのは、そのスクロールビューで(その日のイベントを見るために日付を選んだ)ボタンにアクセスし、その背景色を変更することでした。あなたの便宜のために、日付とスクロールビューのコード全体を追加しました。また、リモートサーバーからデータがロードされていることにも注意してください。
を次のようにスクリーンショットを
リンクを使用すると、タイピング中に何も悪いことを見れば、私を許してくださいです。これは私の最初の質問です。
luckyDateScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(22, 2, lucky_screen_width-45, 23)];
luckyDateScrollView.showsHorizontalScrollIndicator = NO;
CGFloat paperWidth = 50;
int numberOfPapers = [dateRanges count];
for (int i=0; i<[dateRanges count]; i++) {
//NSLog(@"%d: %@", i, dateRange[i]);
//php like exploding with separator |
NSArray *dateString = [dateRanges[i] componentsSeparatedByString:@"|"];
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(5+ (paperWidth+4) * i , 0, paperWidth, luckyDateScrollView.bounds.size.height)];
btn.titleLabel.font = [UIFont fontWithName:@"Arial" size:11.0f];
[btn setTitle: [NSString stringWithFormat:@"%@",dateString[0]] forState:UIControlStateNormal];
//dateResendButton
[btn setTag:i];
[btn addTarget:self
action:@selector(byDateFilterButton:)
forControlEvents:UIControlEventTouchUpInside];
if([today isEqualToString:dateString[1]]){
[GlobalMethods makeRoundedView:btn WithColorString:@"#ffffff" BGColorString:@"#004D00"];
}else{
[GlobalMethods makeRoundedView:btn WithColorString:@"#ffffff" BGColorString:GlobalVariables.initGV.BlackColor];
}
//[GlobalMethods makeRoundedView:btn WithColorString:@"#ffffff" BGColorString:@"#FF0000"];
[luckyDateScrollView addSubview:btn];
}
contentSize = CGSizeMake(10 + (paperWidth+4) * numberOfPapers, luckyDateScrollView.bounds.size.height);
luckyDateScrollView.contentSize = contentSize;
// [GlobalMethods makeRoundedView:aScrollView WithColorString:@"#ffffff" BGColorString:GlobalVariables.initGV.BlackColor];
[dateUIView addSubview:luckyDateScrollView];
luckyDateBtnLeftScroll = [[UIButton alloc] initWithFrame:CGRectMake(5, 2, 20, 23)];
[luckyDateBtnLeftScroll setBackgroundImage:[UIImage imageNamed:@"arrow_g_icon_left"] forState:UIControlStateNormal];
[luckyDateBtnLeftScroll addTarget:self action:@selector(dateSetScrollToLeft:) forControlEvents:UIControlEventTouchUpInside];
[dateUIView addSubview:luckyDateBtnLeftScroll];
luckyDateBtnRightScroll = [[UIButton alloc] initWithFrame:CGRectMake(lucky_screen_width-25, 2, 20, 23)];
[luckyDateBtnRightScroll setBackgroundImage:[UIImage imageNamed:@"arrow_g_icon"] forState:UIControlStateNormal];
[luckyDateBtnRightScroll addTarget:self action:@selector(dateSetScrollToRight:) forControlEvents:UIControlEventTouchUpInside];
[dateUIView addSubview:luckyDateBtnRightScroll];
//ViewCollapse.backgroundColor = [UIColor colorWithCGColor: @"#FFD80D"];
ようこそstackoverflowへようこそ。任意の画像ホスティングウェブサイト(imgur.comなど)に画像をアップロードし、ここにリンクを投稿することができます。 – atulkhatri
ありがとうatulkhatri。私はここにスクリーンショットを追加しました... http://imgur.com/8ptWTRA – tushersuvro
申し訳ありません、これは直接リンクですhttp://i.imgur.com/8ptWTRA.png?1 – tushersuvro