の両方でUIView
とOFFにONであることを確認してきましたあなたは単にUIButtonをサブクラス化し、その中にカスタム図面を実装することができます。 UIButtonは、テーブルビューの接触を妨げずにタスクを実行する最も簡単な方法です。テーブルビューでタップジェスチャーを実装すると、セルに問題が発生します。
カスタム画像(1つの画像として+記号とテキストの両方)を取得し、それを背景画像として使用できます。
コードで描画することもできます。
たとえば、あなたはこの試みることができます:
func drawCanvas1(frame frame: CGRect = CGRectMake(3, 8, 209, 109)) {
//// General Declarations
let context = UIGraphicsGetCurrentContext()
//// Color Declarations
let color = UIColor(red: 0.967, green: 0.423, blue: 0.211, alpha: 1.000)
//// Image Declarations
let screenShot20151111At32900PM = UIImage(named: "screenShot20151111At32900PM.png")!
//// Rectangle Drawing
let rectanglePath = UIBezierPath(roundedRect: CGRectMake(frame.minX + 39, frame.minY + 23, 113, 46), cornerRadius: 8)
color.setFill()
rectanglePath.fill()
//// Rectangle 2 Drawing
let rectangle2Rect = CGRectMake(frame.minX + 51, frame.minY + 27, 33, 34)
let rectangle2Path = UIBezierPath(rect: rectangle2Rect)
CGContextSaveGState(context)
rectangle2Path.addClip()
screenShot20151111At32900PM.drawInRect(CGRectMake(floor(rectangle2Rect.minX - 16 + 0.5), floor(rectangle2Rect.minY - 15 + 0.5), screenShot20151111At32900PM.size.width, screenShot20151111At32900PM.size.height))
CGContextRestoreGState(context)
//// Text Drawing
let textRect = CGRectMake(frame.minX + 97, frame.minY + 23, 73, 46)
let textTextContent = NSString(string: "\nfollow\ntrip\n")
let textStyle = NSParagraphStyle.defaultParagraphStyle().mutableCopy() as! NSMutableParagraphStyle
textStyle.alignment = .Left
let textFontAttributes = [NSFontAttributeName: UIFont.systemFontOfSize(UIFont.labelFontSize()), NSForegroundColorAttributeName: UIColor.whiteColor(), NSParagraphStyleAttributeName: textStyle]
let textTextHeight: CGFloat = textTextContent.boundingRectWithSize(CGSizeMake(textRect.width, CGFloat.infinity), options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: textFontAttributes, context: nil).size.height
CGContextSaveGState(context)
CGContextClipToRect(context, textRect);
textTextContent.drawInRect(CGRectMake(textRect.minX, textRect.minY + (textRect.height - textTextHeight)/2, textRect.width, textTextHeight), withAttributes: textFontAttributes)
CGContextRestoreGState(context)
}
をし、その結果のようなものになります。私のため
![enter image description here](https://i.stack.imgur.com/qGj1yt.png)
あなただけで、オレンジ色の画像を行い、プラスにも、あなたのボタンの背景画像として署名し、右のフォロートリップラベルを揃える、またはすることができますビューと同じサイズのカスタムボタンを追加し、透明な背景とラベルなしでビューに追加することができます。 –
タッチは「UITableView」によって「吸収」されています。代わりに 'UITableView'にジェスチャ認識子を追加し、座標を使用してどのセルとどのボタンがクリックされたかを把握してください。 –
あなたのような実装は完全に機能しています!すべてを正しく設定していますか? –