创建带有关闭按钮的标签

Create a label with close button

我正在寻找创建带有关闭按钮的标签的最佳方法。我需要在标签中放置一个按钮,还是可以将标签用作按钮?

您需要创建一个自定义 UIView 并在特定位置使用触摸来关闭我认为在功能上类似于关闭按钮的 uiview。

要删除该视图,请使用以下代码在 touches begind 方法中识别自定义视图上的触摸:

CGPoint locationPoint = [[touches anyObject] locationInView:buttonlabel];
    if (CGRectContainsPoint(buttonlabel.bounds, [touches.anyObject  locationInView:buttonlabel])==YES){
        if ( (your desired location) ) {

            NSLog(@"pressed close button");
            [buttonlabel removeFromSuperview]; //here when i clicked on top right,only the last view that is added is getting removed

      }