我有一个tableview,我想知道如何更改所选行的文本颜色,比如Red?我试过这段代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell= [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:nil] autorelease];
cell.text = [localArray objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
cityName = [localArray objectAtIndex:indexPath.row];
UITableViewCell* theCell = [tableView cellForRowAtIndexPath:indexPath];
theCell.textColor = [UIColor redColor];
//theCell.textLabel.textColor = [UIColor redColor];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
Run Code Online (Sandbox Code Playgroud)
(1)当我选择任何行时,文本颜色变为红色,但当我选择另一行时,之前选择的行的文本保持红色.我该怎么解决这个问题?
(2)当我滚动表格文字颜色变为黑色时如何解决这个问题?
谢谢..
我有一个PopUpView,我添加到ViewController.
我创建了一个委托方法didTapOnOKPopUp(),这样当我点击PopUpView中的Ok Button时,它应该从使用它的委托的ViewController中删除.
这是PopUpView.Swift的代码
protocol PopUpViewDelegate: class {
func didTapOnOKPopUp()
}
class PopUpView: UIView {
weak var delegate : PopUpViewDelegate?
@IBAction func btnOkPopUpTap(_ sender: UIButton)
{
delegate?.didTapOnOKPopUp()
}
}
Run Code Online (Sandbox Code Playgroud)
这是我使用委托方法的ForgotPasswordViewController的代码.
class ForgotPasswordViewController: UIViewController, PopUpViewDelegate {
// I have created an Instance for the PopUpView and assign Delegate also.
func popUpInstance() -> UIView {
let popUpView = UINib(nibName: "PopUpView", bundle: nil).instantiate(withOwner: nil, options: nil).first as! PopUpView
popUpView.delegate = self
return popUpView …Run Code Online (Sandbox Code Playgroud) 我是 iOS 新手,我陷入了这个问题。我正在创建一个像这样的自定义单元格
我在主视图内拍摄了一个矩形视图(左侧)。这是设置两个视图的圆角半径的代码。
_viewBG.layer.cornerRadius = 10.0;
_viewBG.layer.shadowOpacity = 0.5;
_viewBG.layer.shadowOffset = CGSizeMake(-1, 1);
_viewBG.layer.borderWidth = 0.5;
_viewBG.layer.borderColor = [[UIColor lightGrayColor] CGColor];
UIBezierPath *maskPath = [UIBezierPath
bezierPathWithRoundedRect:self.viewLeft.bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft)
cornerRadii:CGSizeMake(10, 10)
];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.viewLeft.layer.mask = maskLayer;
Run Code Online (Sandbox Code Playgroud)
但我得到这个输出..
所以我想根据主视图设置红色 uiview 的角半径...任何想法将不胜感激。你能帮我吗?
有没有人试图用故事板实现iCarousel?我有一个现有项目,但不确定这是否适用于Storyboard.有没有人成功完成此任务或提供任何指示,我需要在Storyboard项目中实现这一点?
ios ×5
objective-c ×3
uiview ×2
icarousel ×1
iphone ×1
storyboard ×1
swift ×1
uibutton ×1
uitableview ×1
xcode ×1