iphone - How to display 2 lines of text for subtitle of MKAnnotation and change the image for the button on the right? -


i looking @ apple's mapcallouts example map annotations , callouts (==bubbles appear when click on pin). every annotation there has coordinates, title , subtitle. display subtitle in 2 lines, tried with:

- (nsstring *)subtitle { return @"founded: june 29, 1776\nsecond line text"; } 

but text "second line text" stays in 1 line , makes bubble wider.i this:

enter image description here

i change image of button 1 of own's, code sets button this:

uibutton* rightbutton = [uibutton buttonwithtype:uibuttontypedetaildisclosure]; 

any ideas?

edit: tried 7kv7's advice. button change successful, still cant subtitles in 2 lines. code:

mkpinannotationview* custompinview = [[[mkpinannotationview alloc]                                         initwithannotation:annotation reuseidentifier:bridgeannotationidentifier] autorelease];         custompinview.pincolor = mkpinannotationcolorpurple;         custompinview.animatesdrop = yes;           // button         uibutton *button = [uibutton buttonwithtype:uibuttontypecustom];         button.frame = cgrectmake(0, 0, 23, 23);         button.contentverticalalignment = uicontrolcontentverticalalignmentcenter;         button.contenthorizontalalignment = uicontrolcontenthorizontalalignmentcenter;          //uiedgeinsets titleinsets = uiedgeinsetsmake(7.0, -20.0, 7.0, 7.0);         //button.titleedgeinsets = titleinsets;          [button setimage:[uiimage imagenamed:@"ic_phone_default.png"] forstate:uicontrolstatenormal];         //[button setimage:[uiimage imagenamed:@"ic_phone_selected.png"] forstate:uicontrolstateselected];         [button setimage:[uiimage imagenamed:@"ic_phone_selected.png"] forstate:uicontrolstatehighlighted];         [button addtarget:self action:@selector(showdetails:) forcontrolevents:uicontroleventtouchupinside];          custompinview.rightcalloutaccessoryview = button;          //two labels         uiview *leftcav = [[uiview alloc] initwithframe:cgrectmake(0,0,50,50)];         //[leftcav addsubview : button];         uilabel *l1=[[uilabel alloc] init];         l1.frame=cgrectmake(0, 15, 50, 50);         l1.text=@"first line of subtitle";          l1.font=[uifont fontwithname:@"arial rounded mt bold" size:(10.0)];          uilabel *l2=[[uilabel alloc] init];         l2.frame=cgrectmake(0, 30, 50, 50);         l2.text=@"second line of subtitle";         l2.font=[uifont fontwithname:@"arial rounded mt bold" size:(10.0)];         [leftcav addsubview : l1];         [leftcav addsubview : l2];         custompinview.leftcalloutaccessoryview = leftcav;         //custompinview.         custompinview.canshowcallout = yes;          return custompinview; 

i this:

enter image description here

- (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id <mkannotation>)annotation {        mkannotationview *annotationview = [[mkpinannotationview alloc] initwithannotation:annotation reuseidentifier:@"loc"];      // button     uibutton *button = [uibutton buttonwithtype:uibuttontypecustom]; button.frame = cgrectmake(0, 0, 23, 23); button.contentverticalalignment = uicontrolcontentverticalalignmentcenter; button.contenthorizontalalignment = uicontrolcontenthorizontalalignmentcenter;  [button setimage:[uiimage imagenamed:yourimagename] forstate:uicontrolstatenormal]; [advertbutton addtarget:self action:@selector(buttonpress:) forcontrolevents:uicontroleventtouchupinside];  annview.rightcalloutaccessoryview = button;       // image , 2 labels     uiview *leftcav = [[uiview alloc] initwithframe:cgrectmake(0,0,23,23)];     [leftcav addsubview : yourimageview];     [leftcav addsubview : yourfirstlabel];     [leftcav addsubview : yoursecondlabel];     annotationview.leftcalloutaccessoryview = leftcav;      annotationview.canshowcallout = yes;      return pin; } 

update

the default style annotations supports title , subtitle. neither title nor subtitle can include line breaks. cannot without subclassing.

to use custom view review apple's sample code:

http://developer.apple.com/library/ios/#samplecode/weathermap/introduction/intro.html

i think there problem in code

uilabel *l1=[[uilabel alloc] init]; l1.frame=cgrectmake(0, 15, 50, 50); l1.text=@"first line of subtitle";  l1.font=[uifont fontwithname:@"arial rounded mt bold" size:(10.0)];  uilabel *l2=[[uilabel alloc] init]; l2.frame=cgrectmake(0, 30, 50, 50); l2.text=@"second line of subtitle"; l2.font=[uifont fontwithname:@"arial rounded mt bold" size:(10.0)]; [leftcav addsubview : l1]; [leftcav addsubview : l2]; 

l1 has frame (0, 15, 50, 50) , l2 has (0, 30, 50, 50). wont these 2 overlap? mean l1 start y=15 , height 50. when l2 starts 30 may overlap.. can pls check changing frames


Comments