2016-11-15 87 views
2

我正在工作或項目中,我必須給角從左上角和右上角查看。我正在使用它的自動佈局。我的看法寬度爲296這裏是設計左右角的圓角不正確

first cell

按我在這裏的tableview我的代碼的圓角選擇視圖

  let cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) 
      let view_ = cell.viewWithTag(10)! as UIView 
let maskLayer : CAShapeLayer = CAShapeLayer() 
      let maskpath = UIBezierPath(roundedRect: view_.bounds, byRoundingCorners: [.TopLeft,.TopRight], cornerRadii: CGSizeMake(10, 10)) 

      maskLayer.frame = view_.bounds; 
      maskLayer.path = maskpath.CGPath; 

      view_.layer.mask = maskLayer 
      cell.selectionStyle = UITableViewCellSelectionStyle.None 
      return cell 

但我的問題的第一個單元格設計是我得到這個輸出

enter image description here

我給view_.bounds但我不知道爲什麼它需要該視圖的原始幀值。在像iphone 4s和5這樣的小型設備中,它可以完美輸出,但是在大設備中它會像screeshot一樣發生問題。

請幫我一下吧

+0

剛剛刷新你的table in viewdidload()方法你的問題解決 –

+0

定義tableCellView根據設備的屏幕寬度來看view.frame.width * 0.9 –

+0

@MdIbrahimHassan我有同樣的問題,但底部的一面只有左側的工作。右側不顯示角落。我在工作目標c –

回答

0

定義tableCellView的框架在設備屏幕的寬度方面爲UIScreen.main.bounds.width*0.9

1

的問題是,你是太快運行代碼。您的代碼取決於我們知道view_.bounds一個假設:

let maskpath = UIBezierPath(roundedRect: view_.bounds, byRoundingCorners: [.TopLeft,.TopRight], cornerRadii: CGSizeMake(10, 10)) 
maskLayer.frame = view_.bounds; 

但在你的代碼運行的時間,該值尚未最終確定。這裏要記住的是,當他們放入界面時,視圖是調整大小。你想推遲你的代碼,直到view_.bounds已經達到其最終值(也被稱爲佈局)。