2013-09-25 28 views
9

其他人都注意到iOS 7的自定義accessoryView與內置的accessoryTypes不同嗎?iOS 7佈局accessoryView和accessoryType的方式不同嗎?

像這樣:

enter image description here

頂之一被使用來完成:

cell.accessoryView = cell.accessoryButton; 

(其中accessoryButton是一個定製的UIButton),而第二個是使用完成的:

cell.accessoryView = nil; 
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

相同的代碼,相同的應用程序,相同的Xcode,但在iOS 6上運行代替:

enter image description here

這是在SDK中的錯誤?或者我可以通過代碼控制的東西?

+0

已經有一些變化如何自動佈局的作品,看看轉移到ios7的文檔。 (cba找到鏈接抱歉) –

回答

23

如果你是子類的UITableViewCell你可以調整它layoutSubviews

- (void)layoutSubviews { 
    [super layoutSubviews]; 

    CGRect accessoryViewFrame = self.accessoryView.frame; 
    accessoryViewFrame.origin.x = CGRectGetWidth(self.bounds) - CGRectGetWidth(accessoryViewFrame); 
    self.accessoryView.frame = accessoryViewFrame; 
} 
+1

如果你不是繼承細胞? – therealjohn

+2

不再適用於iOS 8? 'accessoryViewFrame.size'和'accessoryViewFrame.origin'的所有值都等於0. – JonSlowCN

+0

是的,從iOS8和iOS9開始,accessoryView框架是「(CGRect)_accessoryFrame =(origin =(x = 0,y = 0) =(width = 0,height = 0))「 –

0

添加而不是accessoryView的子視圖

UIButton *indicatorBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 
indicatorBtn.frame = CGRectMake(cell.contentView.frame.size.width-55, 2, 50, 50); 
[indicatorBtn setBackgroundImage:[UIImage imageNamed:@"right_indicator.png"] 
        forState:UIControlStateNormal]; 
indicatorBtn.backgroundColor = [UIColor clearColor]; 
//indicatorBtn.alpha = 0.5; 
indicatorBtn.tag = indexPath.row; 
[indicatorBtnaddTarget:self action:@selector(method:) 
    forControlEvents:UIControlEventTouchUpInside]; 

[cell.contentView addSubview:indicatorBtn]; 
相關問題