I had created a UIMapView and set delegate, but it's not called delegate of mapview.
#import <MapKit/MapKit.h>
#interface MapViewController : UIView <MKMapViewDelegate>
- (id)initWith_Latitude:(NSString *)Latitude Longitude:(NSString *)Longitude;
- (id)initWith_Latitude:(NSString *)Latitude Longitude:(NSString *)Longitude
{
CGRect frame = CGRectMake(0, 0, 200, 200);
self = [super initWithFrame:frame];
if (self) {
// Initialization code
mapView = [[MKMapView alloc] initWithFrame:frame];
MKCoordinateRegion mapRegion;
[mapView setUserInteractionEnabled:YES];
[mapView setDelegate:self];
mapRegion.center.latitude = [Latitude doubleValue];
mapRegion.center.longitude = [Longitude doubleValue];
mapRegion.span.latitudeDelta = 0.005;
mapRegion.span.longitudeDelta = 0.005;
mapView.region = mapRegion;
[self addSubview:mapView];
}
return self;
}
delegate is not called:
- (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView2 fullyRendered:(BOOL)fullyRendered{
NSLog(#"abc...");
}
How to I can resolve this problem, please help me.
Related
google maps could not zoom to current Location
after searching for many solution over stack such as Zoom in to current location on map in object c but i found a solution could help me but it was written in swift
Current Location in Google Maps with swift
Code
.h File
#import <UIKit/UIKit.h>
#import GoogleMaps;
#interface BranchesViewController : UIViewController <GMSMapViewDelegate,CLLocationManagerDelegate>
#property (weak, nonatomic) IBOutlet GMSMapView *mapView;
#property (nonatomic, retain) CLLocationManager *locationManager;
#end
.m File
//
// BranchesViewController.m
// Geeks Diner
//
// Created by Zakaria Darwish on 5/15/16.
// Copyright © 2016 CodeBee. All rights reserved.
//
#import "BranchesViewController.h"
#import "infoWindow.h"
#import "SplashViewController.h"
#import "sharedVariables.h"
#import"AFNetworking.h"
#import "UIWebView+AFNetworking.h"
#import "SDWebImageCompat.h"
#import "SDWebImageDownloaderOperation.h"
#import "SDWebImageDownloader.h"
#import "MyGeeksTableViewController.h"
#import "GeeksLocations.h"
#import "BranchDetailsViewController.h"
#import GoogleMaps;
#interface BranchesViewController () <GMSMapViewDelegate>
#end
#implementation BranchesViewController
{
GMSMarker *marker_1;
BOOL firstLocationUpdate_;
CLLocationCoordinate2D *startPoint;
CLLocation *myLocation;
NSMutableArray *list;
}
-(void)getCurrentLocationAndZoomToIt {
}
//- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:newLocation.coordinate.latitude
// longitude:newLocation.coordinate.longitude
// zoom:17.0];
// [self.mapView animateToCameraPosition:camera];
// CLLocation *location = newLocation;
//
//
//
//
//
////
//// let userLocation = locations.last
//// let center = CLLocationCoordinate2D(latitude: userLocation!.coordinate.latitude, longitude: userLocation!.coordinate.longitude)
////
//// let camera = GMSCameraPosition.cameraWithLatitude(userLocation!.coordinate.latitude,
//// longitude: userLocation!.coordinate.longitude, zoom: 8)
//// let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
//// mapView.myLocationEnabled = true
//// self.view = mapView
////
//// let marker = GMSMarker()
//// marker.position = center
//// marker.title = "Current Location"
//// marker.snippet = "XXX"
//// marker.map = mapView
////
//// locationManager.stopUpdatingLocation()
// }
-(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker
{
NSLog(#"tapped");
// we need to move into new view //
BranchDetailsViewController *avc = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"branchdetailviewcontroller"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:avc];
// nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:nav animated:YES completion:nil];
}
-(UIImage *)getImage :(UIImage *)icon stop:(NSString *)stopNumber color:(UIColor *)color
{
// create label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, icon.size.width,icon.size.height)];
[label setText:stopNumber];
[label setTextColor:color];
[label setFont:[UIFont boldSystemFontOfSize:11]];
label.textAlignment = NSTextAlignmentCenter;
//start drawing
UIGraphicsBeginImageContext(icon.size);
//draw image
[icon drawInRect:CGRectMake(0, 0, icon.size.width, icon.size.height)];
//draw label
[label drawTextInRect:CGRectMake((icon.size.width - label.frame.size.width)/2, -5, label.frame.size.width, label.frame.size.height)];
//get the final image
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView.delegate = self;
self.locationManager = [[CLLocationManager alloc] init] ;
self.locationManager.delegate = self;
[self.locationManager requestWhenInUseAuthorization];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation ;
[self.locationManager setDistanceFilter:10.0f] ;
[self.locationManager startUpdatingLocation];
// UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]];
// // Width equivalent to system default Done button's (which appears on pushed view in my case).
// rightBarButtonItem.enabled = NO;
// self.navigationItem.leftBarButtonItem = rightBarButtonItem;
[self getGeeksLocations];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
[self.locationManager stopUpdatingLocation];
CLLocationCoordinate2D zoomLocation;
// zoomLocation.latitude = self.mapView.myLocation.location.coordinate.latitude;
// zoomLocation.longitude= YourMapView.userLocation.location.coordinate.longitude;
// 2
// MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*1609.344, 0.5*1609.344);
// 3
// [self.mapView setRegion:viewRegion animated:YES];
// [self.locationManager stopUpdatingLocation];
// zoomLocation.latitude = self.mapView.userLocation.location.coordinate.latitude;
// zoomLocation.longitude= self.mapView.userLocation.location.coordinate.longitude;
// // 2
// MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*1609.344, 0.5*1609.344);
// // 3
// [self.mapView setRegion:viewRegion animated:YES];
}
so any one could help me with that ??
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
mapView.animate(toLocation: CLLocationCoordinate2D(latitude: locValue.latitude, longitude: locValue.longitude))
mapView.setMinZoom(4.6, maxZoom: 20)
}
You can pan the map or change its perspective with very little latency. The bearing, tilt, location and zoom level of the map can be controlled programmatically via the GMSCameraPosition object.
You can use -animateToZoom: on your GMSMapView, or you can create a GMSCameraPosition and set the coordinate and zoom level and then use -animateToCameraPosition: or create a GMSCameraUpdate and then use -animateWithCameraUpdate:
GMSCameraPosition *cameraPosition = [GMSCameraPosition cameraWithLatitude:latitude
longitude:longitude
zoom:11.0];
[self.mapView animateToCameraPosition:cameraPosition];
or
GMSCameraUpdate *update = [GMSCameraUpdate zoomTo:11.0];
[self.mapView animateWithCameraUpdate:update];
or
[self.mapView animateToZoom:11.0];
I had created a MKMapView and set delegate for this. But, it's not called delegate for this MKMapView.
- (id)initWith_latitudeObject:(NSString *)latitudeObject longitudeObject:(NSString *)longitudeObject fromUser:(NSString *)fromUser
{
CGRect frame = CGRectMake(0, 0, 200, 200);
self = [super initWithFrame:frame];
if (self) {
// Initialization code
_mkMapView = [[MKMapView alloc] initWithFrame:frame];
[_mkMapView setDelegate:self];
MKCoordinateRegion mapRegion;
mapRegion.center.latitude = [latitudeObject doubleValue];
mapRegion.center.longitude = [longitudeObject doubleValue];
mapRegion.span.latitudeDelta = 0.005;
mapRegion.span.longitudeDelta = 0.005;
_mkMapView.region = mapRegion;
[self addSubview:_mkMapView];
[self getLocationMapView];
}
return self;
}
It's not call:
- (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered{
UIImage *img = [self renderToImage:mapView];
}
How to I can resolve this problem! Please help me.
I had set delegate for this, but it's not called delegate for this MKMapView
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want this type of output for ios Application. I hadn't any idea how to do it. Please let me know if anyone know how to do it.
EDIT
I had updated my code as per answer, but still it was not working. I can't unserstand that how UIView display and what will be its size ?
#import <UIKit/UIKit.h>
#interface MyView : UIView
#end
#import "MyView.h"
#implementation MyView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code
// initilize all your UIView components
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(20,30, 200, 44)];
label1.text = #"i am label 1";
[self addSubview:label1]; //add label1 to your custom view
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(20,80, 200, 44)];
label2.text = #"i am label 2";
[self addSubview:label2]; //add label2 to your custom view
}
return self;
}
=================================================
#import <MapKit/MapKit.h>
#import "MyView.h"
#interface MyCustomView : MKAnnotationView
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event;
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event;
- (void)setShowCustomCallout:(BOOL)showCustomCallout animated:(BOOL)animated;
- (void)setShowCustomCallout:(BOOL)showCustomCallout
;
#property(strong, nonatomic) MyView *calloutView ;
#end
#import "MyCustomView.h"
#implementation MyCustomView
- (void)setShowCustomCallout:(BOOL)showCustomCallout
{
[self setShowCustomCallout:showCustomCallout animated:NO];
}
- (void)setShowCustomCallout:(BOOL)showCustomCallout animated:(BOOL)animated
{
//if (showCustomCallout == showCustomCallout) return;
showCustomCallout = showCustomCallout;
void (^animationBlock)(void) = nil;
void (^completionBlock)(BOOL finished) = nil;
if (showCustomCallout)
{
self.calloutView.alpha = 0.0f;
animationBlock = ^{
self.calloutView.alpha = 1.0f;
[self addSubview:self.calloutView];
};
} else {
animationBlock = ^{ self.calloutView.alpha = 0.0f; };
completionBlock = ^(BOOL finished) { [self.calloutView removeFromSuperview]; };
}
if (animated) {
[UIView animateWithDuration:0.2f animations:animationBlock completion:completionBlock];
} else {
animationBlock();
completionBlock(YES);
}
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *view = [super hitTest:point withEvent:event];
if ([view isKindOfClass:_calloutView.class]) {
return nil; // todo: add a new delegate method to the map protocol to handle callout taps
} else {
return view;
}
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event
{
CGRect rect = self.bounds;
BOOL isInside = CGRectContainsPoint(rect, point);
if(!isInside)
{
for (UIView *view in self.subviews)
{
isInside = CGRectContainsPoint(view.frame, point);
if(isInside)
break;
}
}
return isInside;
}
=================================================
#import "ViewController.h"
#interface ViewController ()
{
CLLocationManager *locationManager;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; //whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[locationManager requestWhenInUseAuthorization]; // Add This Line
[locationManager startUpdatingLocation];
_mapView.showsUserLocation = YES;
_mapView.delegate = self;
CLLocationCoordinate2D annotationCoord;
annotationCoord.latitude = 23.041261;
annotationCoord.longitude = 72.513892;
_mapView.region = MKCoordinateRegionMakeWithDistance(annotationCoord, 800, 800);
// MKCoordinateRegion adjustedRegion = [_mapView regionThatFits:MKCoordinateRegionMakeWithDistance(annotationCoord, 800, 800)];
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = #"I am here";
annotationPoint.subtitle = #"Microsoft's headquarters";
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView1 viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:#"pin"];
annView.pinColor = MKPinAnnotationColorGreen;
return annView;
}
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
[((MyCustomView *)view) setShowCustomCallout:NO animated:YES];
}
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
MyCustomView *annotationView = [[MyCustomView alloc]init];
[annotationView setShowCustomCallout:YES animated:YES];
}
You have to make a custom view to make a custom callout on mapview.you have to make a class that contain a custom view which will be on pin tapped . Here is the sample code on github.
https://gist.github.com/ShadoFlameX/7495098
I have created 4 type of annotation group. In the map UI, I also added a tab bar on the bottom as my button.
My tab bar is used to filter out the annotation in MapKit.
For example... I have 4 group of annotation and 4 tab bar item.
When I clicked tab bar item 1, it show only 1 group of annotation in MapKit, other group of annotation will hide/remove in MapKit but I failed to achieve this kind of work.
My code:
in MapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#interface MapViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate , UITabBarDelegate>{
IBOutlet UITabBar *tabBar;
}
#property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
#property (strong, nonatomic) CLLocationManager *locationManager;
#end
my mapViewController.m:
#import "MapViewController.h"
#import "SWRevealViewController.h"
#import "Annotation.h"
#interface MapViewController ()<CLLocationManagerDelegate>
#end
//set desitination of map
#define PENANG_LATI 5.419501;
#define PENANG_LONG 100.323264;
//shop
#define SHOP_LATI 5.419501;
#define SHOP_LONG 100.323264;
//cafe
#define CAFE_LATI 5.419917;
#define CAFE_LONG 100.322969;
//food
#define FOOD_LATI 5.419746;
#define FOOD_LONG 100.322610;
//mural
#define MURAL_LATI 5.419786;
#define MURAL_LONG 100.322510;
#define THE_SPAN 0.005f;
#implementation MapViewController
#synthesize mapView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//tabBar
tabBar.delegate = self;
MKCoordinateRegion myRegion;
//Center
CLLocationCoordinate2D center;
center.latitude = PENANG_LATI;
center.longitude = PENANG_LONG;
//SPAN
MKCoordinateSpan span;
span.latitudeDelta = THE_SPAN;
span.longitudeDelta = THE_SPAN;
myRegion.center = center;
myRegion.span = span;
//set map
[mapView setRegion:myRegion animated:YES];
SWRevealViewController *revealViewController = self.revealViewController;
if ( revealViewController )
{
[self.sidebarButton setTarget: self.revealViewController];
[self.sidebarButton setAction: #selector( revealToggle: )];
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
/*
//create coordinate
CLLocationCoordinate2D penangLocation;
penangLocation.latitude = PENANG_LATI;
penangLocation.longitude = PENANG_LONG;
Annotation * myAnnotation = [Annotation alloc];
myAnnotation.coordinate = penangLocation;
myAnnotation.title = #"THE ONE ACADEMY PENANG";
myAnnotation.subtitle = #"HELLO!! I STUDY HERE";
[self.mapView addAnnotation:myAnnotation];
*/
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
//my group of annotation location
NSMutableArray * myShop = [[NSMutableArray alloc] init];
NSMutableArray * myCafe = [[NSMutableArray alloc] init];
NSMutableArray * myFood = [[NSMutableArray alloc] init];
NSMutableArray * myMural = [[NSMutableArray alloc] init];
CLLocationCoordinate2D penangLocation;
Annotation * myShopAnnotation;
Annotation * myCafeAnnotation;
Annotation * myFoodAnnotation;
Annotation * myMuralAnnotation;
//shop location
myShopAnnotation = [[Annotation alloc] init];
penangLocation.latitude = SHOP_LATI;
penangLocation.longitude = SHOP_LONG;
myShopAnnotation.coordinate = penangLocation;
myShopAnnotation.title = #"Shop";
myShopAnnotation.subtitle = #"I study here";
[myShop addObject:myShopAnnotation];
//cafe location
myCafeAnnotation = [[Annotation alloc] init];
penangLocation.latitude = CAFE_LATI;
penangLocation.longitude = CAFE_LONG;
myCafeAnnotation.coordinate = penangLocation;
myCafeAnnotation.title = #"Cafe";
myCafeAnnotation.subtitle = #"I paid here";
[myCafe addObject:myCafeAnnotation];
//food location
myFoodAnnotation = [[Annotation alloc] init];
penangLocation.latitude = FOOD_LATI;
penangLocation.longitude = FOOD_LONG;
myFoodAnnotation.coordinate = penangLocation;
myFoodAnnotation.title = #"Food";
myFoodAnnotation.subtitle = #"I walk here";
[myFood addObject:myFoodAnnotation];
//Mural location
myMuralAnnotation = [[Annotation alloc] init];
penangLocation.latitude = MURAL_LATI;
penangLocation.longitude = MURAL_LONG;
myMuralAnnotation.coordinate = penangLocation;
myMuralAnnotation.title = #"Mural";
myMuralAnnotation.subtitle = #"I walk here";
[myMural addObject:myMuralAnnotation];
if(item.tag == 1)
{
//show and hide annotation
NSLog(#"shop");
[mapView addAnnotations:myShop];
[mapView removeAnnotations:myCafe];
[mapView removeAnnotations:myFood];
[mapView removeAnnotations:myMural];
}
if(item.tag == 2)
{
//show and hide annotation
NSLog(#"cafe");
[mapView removeAnnotations:myShop];
[mapView addAnnotations:myCafe];
[mapView removeAnnotations:myFood];
[mapView removeAnnotations:myMural];
}
if(item.tag == 3)
{
//show and hide annotation
NSLog(#"food");
[mapView removeAnnotations:myShop];
[mapView removeAnnotations:myCafe];
[mapView removeAnnotations:myFood];
[mapView addAnnotations:myMural];
}
if(item.tag == 4)
{
//show and hide annotation
NSLog(#"mural");
[mapView removeAnnotations:myShop];
[mapView removeAnnotations:myCafe];
[mapView removeAnnotations:myFood];
[mapView addAnnotations:myMural];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
When removeAnnotations: is called like this:
[mapView removeAnnotations:myCafe];
the map view looks for the exact objects (using pointer comparison) in myCafe that are already on the map.
The map view here does not match up annotations using their coordinate, title, etc.
Since the code creates new instances of each annotation every time a selection is made, the new instances are not found on the map and so removeAnnotations: does nothing.
Instead, in your case, you could just tell the map view to remove all existing annotations and then add the new annotations based on the current selection.
Instead of this:
[mapView addAnnotations:myShop];
[mapView removeAnnotations:myCafe];
[mapView removeAnnotations:myFood];
[mapView removeAnnotations:myMural];
do this:
[mapView removeAnnotations:mapView.annotations]; //remove all
[mapView addAnnotations:myShop]; //then add new
The code could be simplified as well by using a switch statement and in each case, only create the annotations needed for the selection (you don't need to create all annotations every time).
I am making an iPhone application that uses a GMSMapView and I want to be able to add a toolbar on top of the map. This is my code:
#import "MapViewController.h"
#import <GoogleMaps/GoogleMaps.h>
#interface MapViewController ()
#end
#implementation MapViewController
{
GMSMapView *mapView_;
id<GMSMarker> myMarker;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)back:(id)sender
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
// You don't need to modify the default initWithNibName:bundle: method.
- (void)loadView
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:30.616083 longitude:-96.338908 zoom:13];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
mapView_.delegate = self;
self.view = mapView_;
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = CLLocationCoordinate2DMake(30.616083, -96.338908);
options.title = #"College Station";
options.snippet = #"Texas";
[mapView_ addMarkerWithOptions:options];
}
#pragma mark - GMSMapViewDelegate
- (void)mapView:(GMSMapView *)mapView
didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
[myMarker remove];
NSLog(#"You tapped at %f,%f", coordinate.latitude, coordinate.longitude);
GMSMarkerOptions *marker = [[GMSMarkerOptions alloc] init];
marker.position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);
marker.title = #"Tap Event";
// (icon for marker) marker.icon = [UIImage imageNamed:#"house"];
myMarker = [mapView_ addMarkerWithOptions:marker];
}
#end
In my storyboard i have a toolbar but I do not know how to get it to be displayed over the GMSMapView. Im new to iOS and have searched for solutions online but haven't had any luck with GMSMapView.
Because you set the view to the mapView_, the view made in StoryBoard is overriden. I've added a toolbar with an Segmented Control and an button using the following code:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UINavigationBar *navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, screenBounds.size.width, 44)];
UINavigationItem *navItems = [[UINavigationItem alloc]init];
UIBarButtonItem *barButtonRight = [[UIBarButtonItem alloc]initWithTitle:#"" style:UIBarButtonItemStylePlain target:self action:#selector(SettingsButtonPressed)];
UISegmentedControll *segControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:#"Opt1",#"Opt2",#"Opt3", nil]];
UIImage *imageSettings= [UIImage imageNamed:#"36-toolbox.png"];
[segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
[segControl setSelectedSegmentIndex:0];
[segControl setFrame:CGRectMake(10, 5, 150, 32)];
[segControl addTarget:self action:#selector(KiesVC:) forControlEvents:UIControlEventValueChanged];
[barButtonRight setImage:imageSettings];
[navItems setRightBarButtonItem:barButtonRight];
[navItems setTitleView:segControl];
[navBar setItems:[NSArray arrayWithObject:navItems] animated:NO];
You then add the toolbar by calling :
[self.view addSubview:navBar];
Hope it helps