Я искал повсюду за последнее полчаса, пытаясь найти способ создания кнопки с закругленными углами, которые могут иметь пользовательскую RgB фон ...Установить цвет фона RGB UIColor ButtonTypeRoundedRect
Это то, что я в настоящее время, но ясно, что она не работает:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
tableView.separatorColor = [UIColor clearColor];
NSString *CellIdentifier = @"TimesCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//[cell sizeToFit];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(customActionPressed:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Custom Action" forState:UIControlStateNormal];
[button setTitleEdgeInsets:UIEdgeInsetsMake(-10.0f, 0.0f, 0.0f, 0.0f)];
button.frame = CGRectMake(5, 5, 310, 50);
int r = 255-1;
int g = 255-180;
int b = 7-1;
NSLog(@"%i", 180+(int)((g/5)*(indexPath.row+1)));
UIColor *thisColor = [UIColor colorWithRed:1+(int)((r/5)*(indexPath.row+1)) green:180+(int)((g/5)*(indexPath.row+1)) blue:1+(int)((b/5)*(indexPath.row+1)) alpha:1];
button.backgroundColor = thisColor;
button.clipsToBounds = YES;
button.layer.cornerRadius = 15;
[cell addSubview:button];
return cell;
}
Я видел кучу вещей о том, как вы не можете установить цвет фона на roundedRect и как это исправить, но я должны иметь возможность динамически генерировать цвет, как вы можете видеть в коде ...
В настоящее время он просто не имеет цвета фона для кнопок. Интересно, что если я использую [UIColor colorColor]
, он работает просто отлично, это просто RGB, который отбрасывает его.
Как я могу это сделать в своей ситуации?
Вы должны описать, что это не так ... – Wain
вы можете взять кнопки как UIButtonTypeCustom – guptha
@wain Done ..... – maxhud