回答
假設您在UIView中繪製該圓,您可以創建自定義按鈕並將其添加到您的視圖。
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(100, 100, 100, 30);
[yourView addSubView:button];
[button addTarget:self action:@selector(yourEventTobeFired) forControlEvents:UIControlEventTouchUpInside];
那就是它。
我只在一個視圖上繪製圓。但是該圓是基於矩形框中的半徑繪製的。我怎樣才能把一個按鈕放在一個圓上? – user1278228
你可以請添加你的代碼嗎? –
以下是用於繪製圓的代碼。圓形繪製。但希望可以點擊。 CGContextSetLineWidth(context,5.0); if(needColor)CGContextSetStrokeColorWithColor(context,[UIColor blueColor] .CGColor); else CGContextSetStrokeColorWithColor(context,[UIColor clearColor] .CGColor); CGContextAddEllipseInRect(context,rect); CGContextSetFillColorWithColor(context,[UIColor redColor] .CGColor); CGContextFillEllipseInRect(context,rect); CGContextStrokePath(context); – user1278228
我知道這個問題很老,但我想把我的兩毛錢扔在那裏。我認爲使用按鈕可以讓您更容易完成任務,如Jennis
所示。但是,他的按鈕不是很圓。
需要更改以製作按鈕的屬性爲.cornerRadius
。以下是這可以使用Jennis'的代碼示例來完成:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.layer.backgroundColor = [UIColor colorWithWhite:0.2f alpha:.5f].CGColor;
button.frame = CGRectMake(x, y, width, height);
button.layer.cornerRadius = 20; //key to rounded button
[[self view] addSubview:button];
[button addTarget:self action:@selector(yourEventTobeFired) forControlEvents:UIControlEventTouchUpInside];
而導致這段代碼的輸出:
此按鈕可點擊,並在點擊它會調用該方法yourEventTobeFired
如果您拒絕使用按鈕,那麼我建議您在自定義繪圖中添加gesture recognizer
,因爲我不相信您可以像添加按鈕那樣添加action
。
- 1. 畫布可以點擊嗎?
- 2. 可點擊的線條和圓圈與HTML畫布
- 3. 在iOS中畫圓圈
- 4. 在圓圈畫布上點擊鼠標並畫線?
- 5. 在鼠標點擊畫布上畫一個實心圓圈
- 6. 動畫 - 在iOS中繪製圓圈 - 未完成圓圈動畫
- 7. 可以點擊
- 8. 爲什麼在我點擊的地方不會畫圓圈
- 9. JavaScript的畫布元素 - 檢查是否點擊圈元素
- 10. 檢測用戶是否點擊畫布內的任意圓圈
- 11. 繪製在畫布的圓圈上點擊鼠標
- 12. 如何獲取在畫布上點擊的圓圈
- 13. 在iOS中的UIMenuController中可以使UIMenuItem不可點擊嗎?
- 14. 我可以在圈內生成點嗎?
- 15. 可點擊的圖像內的畫布
- 16. 點擊畫布點擊
- 17. 圓圈蒙面視圖動畫速度太快,無法點擊
- 18. 如何顯示圓圈動畫上點擊android系統
- 19. jQuery - 可以在href上點擊點擊
- 20. 可以從點擊類從點擊ID
- 21. 設置一個可以點擊的畫布的某個區域
- 22. 使用畫布可點擊的位圖
- 23. JavaFX - 畫布上的可點擊線
- 24. 動畫後可點擊的區域
- 25. iOS 5 - 觸摸畫一個圓圈
- 26. 更改畫布中圓圈的起點?
- 27. iOS按鈕可見,不可點擊
- 28. 綁定動畫屬性以點擊ItemsControl內的可視項目
- 29. 動畫UIButtons可以在目標點擊前到達目的地
- 30. 在iOS中畫圓圈動畫用圓形筆畫
必須要愛這個人 –