2015-11-11 129 views
2

我在單元格和文本右側也有一個按鈕。文本與按鈕重疊。我希望文本在觸摸按鈕之前進入下一行。我會怎麼做?任何方法來解決按鈕和文本的重疊?

enter image description here

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 


    let cell = table.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! ProfileMusicCell 



    cell.customtitle.text = ret[indexPath.row] 
    cell.customartist.text = ter[indexPath.row] 
    cell.customtitle.font = UIFont(name: "Lombok", size: 22) 
    cell.customtitle.textColor = UIColorFromRGB("4A90E2") 
    cell.customartist.font = UIFont(name: "Lombok", size: 16) 
    cell.customartist.textColor = UIColor.blackColor() 


     cell.playbutton.tag = indexPath.row 
    cell.playbutton.addTarget(self, action: "playmusic:", forControlEvents: .TouchUpInside) 




    cell.contentView.addSubview(playButton) 


    cell.textLabel?.numberOfLines = 0; 
    cell.textLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping 

    cell.backgroundColor = UIColor.clearColor() 
    return cell 
} 

    func playmymusic(sender: UIButton!) { 

    let playButtonrow = sender.tag 

    print(ret[playButtonrow]) 
    print(ter[playButtonrow]) 
} 
+0

你有沒有嘗試重新設置按鈕的約束,並重新插入它們基於按鈕的位置?我有一個導航欄和一個視圖類似的問題,經過一個下午的搜索,我發現這是唯一的解決方案。 – Korpel

+0

我不明白你的意思 – xxtmanxx

+1

''playButton.frame = CGRectMake(230,20,100,100)'''''''''''''''''''',我的意思是你沒有利用自動佈局。如果用戶更改設備問題將會發生 – Korpel

回答

1

您可以爲您的UILabel和UIButton的設置框,如:

cell.detailTextLabel.frame = CGRectMake(cell.detailTextLabel.frame.origin.x, cell.detailTextLabel.frame.origin.y, self.frame.size.width - playButton.frame.size.with - cell.detailTextLabel.frame.origin.y, cell.detailTextLabel.frame.height) 

但是,我認爲你應該爲自己創建一個自定義的UITableViewCell,在那裏,你可以使用自動佈局,它更好