Button action in mkannotation view not working?

后端 未结 1 1766
执笔经年
执笔经年 2020-12-01 17:45

Hello i have stuck in one situation on map where i have managed to show custom annotation. When the annotation is tapped i have to show a view with some information and one

相关标签:
1条回答
  • 2020-12-01 18:12

    You need to set frame for this button. which is not really seen in the code. Adjust frame as you want by x position and y position.

    UIButton *tembtn=[UIButton buttonWithType:UIButtonTypeCustom];
    
    // Frame required to render on position and size. Add below line 
    [tembtn setFrame:CGRectMake(0, 0, 100, 50)];
    
    [tembtn setTitle:@"More info" forState:UIControlStateNormal];
    [tembtn addTarget:self action:@selector(annotationBtnAction:)
     forControlEvents:UIControlEventTouchUpInside];
    tembtn.backgroundColor=[UIColor grayColor];
    [view addSubview:tembtn];
    

    Edit:

    Found the reason you can only tap on area, in which annotation is rendered.

    Here is simple demo for custom call out:

    Custom Callout Demo

    enter image description here

    0 讨论(0)
提交回复
热议问题