I need to hide previews image, how can i fix it?
https://i.stack.imgur.com/sjlvD.gif
//create inner tab bar item
self.innerTabBarItem = [[UIButton alloc] init];
[self addSubview:self.innerTabBarItem];
self.innerTabBarItem.userInteractionEnabled = NO;//allows for clicks to pass through to the button below
self.innerTabBarItem.translatesAutoresizingMaskIntoConstraints = NO;
//create selected icon
self.selectedImageView = [[UIImageView alloc] initWithImage:selectedImage];
self.selectedImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.innerTabBarItem addSubview:self.selectedImageView];
//create unselected icon
self.unselectedImageView = [[UIImageView alloc] initWithImage:unselectedImage];
self.unselectedImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.innerTabBarItem addSubview:self.unselectedImageView];
Related
I want leftCalloutAccessoryView have a location's own image, I know how to make a leftCalloutAccessoryView on callout bubble, however I couldn't get the image path
location information is init form a SpotAnnotation class, like bellow
- (id) initWithTitle:(NSString *)aTitle latitude:(CLLocationDegrees)aLat longitude:(CLLocationDegrees)aLon imageName:(UIImage *)imgName{
self.coordinate = CLLocationCoordinate2DMake(aLat, aLon);
self.currentTitle = aTitle;
self.places = [[NSMutableArray alloc] initWithCapacity:0];
self.image = imgName;
return self; }
In ViewController works like this
- (NSArray *) spots{
SpotAnnotation *s1 = [[SpotAnnotation alloc] initWithTitle:#"TaipeiZoo" latitude:25.039550 longitude:121.560265 imageName:[UIImage imageNamed:#"taipeiZoo.jpg"]];
SpotAnnotation *s2 = [[SpotAnnotation alloc] initWithTitle:#"Eslite" latitude:25.039720 longitude:121.565874 imageName:[UIImage imageNamed:#"Eslite.jpg"]]; }
biggest question is here -> initWithImage:
UIImageView *leftIconView = [[UIImageView alloc] initWithImage:"how can I get image path here"];
leftIconView.frame = CGRectMake(10, 10, 50, 50);
pin.leftCalloutAccessoryView = leftIconView;
ummm... I solved it..
UIImageView *leftIconView = [[UIImageView alloc] initWithImage:((SpotAnnotation *)annotation).image];
leftIconView.frame = CGRectMake(0, 0, 50, 50);
leftIconView.contentMode = UIViewContentModeScaleAspectFit;
pin.leftCalloutAccessoryView = leftIconView;
problem is initWithImage:((SpotAnnotation *)annotation).image
I will try hard to get it understand!
I was using PSButtonCell's for links but three individual ones took up too much space so I'm trying to create a custom cell with three buttons in one row; basically like 3 floating icons.
I've got some code for creating a tableview with icons, but currently I do not know how to space them properly (all the icons currently overlap), and I have no idea how I should go about adding tap listeners to the views. Does this look like something I could modify to do what I want? If not does anyone have a better solution they could provide for me? thanks a lot heres my code for the icons
- (id)tableView:(id)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 1) {
UIView *headerView = [[UIView alloc] initWithFrame:(CGRect){{0, 0}, {320, kHeaderHeight}}];
headerView.backgroundColor = UIColor.clearColor;
headerView.clipsToBounds = YES;
// icon
UIImage *bugicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/Bug.png", kSelfBundlePath]];
UIImageView *bugiconView = [[UIImageView alloc] initWithImage:bugicon];
bugiconView.frame = (CGRect){{0, 21}, bugiconView.frame.size};
// bugiconView.center = (CGPoint){headerView.center.x, bugiconView.center.y};
bugiconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[headerView addSubview:bugiconView];
UIImage *payicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/Paypal.png", kSelfBundlePath]];
UIImageView *payiconView = [[UIImageView alloc] initWithImage:payicon];
payiconView.frame = (CGRect){{0, 21}, payiconView.frame.size};
// payiconView.center = (CGPoint){headerView.center.x, payiconView.center.y};
payiconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[headerView addSubview:payiconView];
UIImage *btcicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/bitcoin.png", kSelfBundlePath]];
UIImageView *btciconView = [[UIImageView alloc] initWithImage:btcicon];
btciconView.frame = (CGRect){{0, 21}, btciconView.frame.size};
// btciconView.center = (CGPoint){headerView.center.x, btciconView.center.y};
btciconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[headerView addSubview:btciconView];
You're adding all the subview is in same position. All UIView frame start from same 'x' position '0'. You need to change 2nd and 3rd frame x positon . ( Change your CGRect 'X' position) for second and third UIView.
bugiconView.frame = (CGRect){{0, 21}, bugiconView.frame.size};
payiconView.frame = (CGRect){{0, 21}, payiconView.frame.size};
btciconView.frame = (CGRect){{0, 21}, btciconView.frame.size};
Hope it helps...
I'd like to have a method display an image. My view controller calls the method:
eduPopup *thisEduPopup = [[eduPopup alloc] init];
[thisEduPopup displayPopup];
In the method I have:
-(void) displayPopup {
UIImageView *thisImage = [[UIImageView alloc] init];
thisImage.image = [UIImage imageNamed:#"referral_eduscreen_text_solid.png"];
thisImage.frame = CGRectMake(0, 0, thisImage.image.size.width, thisImage.image.size.height);
[self.superview addSubview:thisImage];
}
...but I get nothing. Is self.superview the right reference? What I should be putting there?
I have been playing around with adding an AwesomeMenu button to my UITabBar. My plan is to have the icons arc above the tab bar with looks pretty cool. I have played with it a bit and have been able to get the icons to display. I to call the menu, I just used the same button that I already had, added an AwesomeMenu behind the tab bar (so the icons bounce up from behind) then hid the Awesome menu. I added an action to my button in the tab bar to simulate a tap on the awesome menu, as well as show the AwesomeMenu, which then shows the buttons perfectly. The problem is that when I try to tap on any of these button, nothing happens. I assume that this is a problem because they are above the UITabBar, but I cannot be sure. I have added a normal AwesomeMenu in the middle of a blank view controller with the same set up as I have on the tab bar (except being on a tab bar and being called by another button) and it works. When I press a button, they work. Based on this, I figure that it is a problem with the buttons being displayed above the UITabBar or maybe simply the way the buttons work. Any help would be very much appreciated!
Here is how I add the button to the UITabBar (pretty standard):
UIImage *storyMenuItemImage = [UIImage imageNamed:#"Selector_Fill.png"];
UIImage *scaledImage = [UIImage imageWithCGImage:[storyMenuItemImage CGImage] scale:(storyMenuItemImage.scale * 2.0) orientation:UIImageOrientationUp];
UIImage *storyMenuItemImagePressed = [UIImage imageNamed:#"Selector_Fill.png"];
UIImage *starImage = [UIImage imageNamed:#"Selector_Camera_Fill"];
AwesomeMenuItem *starMenuItem1 = [[AwesomeMenuItem alloc] initWithImage:scaledImage
highlightedImage:storyMenuItemImagePressed
ContentImage:[UIImage imageNamed:#"Selector_Camera_Fill"]
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem2 = [[AwesomeMenuItem alloc] initWithImage:scaledImage
highlightedImage:storyMenuItemImagePressed
ContentImage:[UIImage imageNamed:#"Selector_Video_Fill"]
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem3 = [[AwesomeMenuItem alloc] initWithImage:scaledImage
highlightedImage:storyMenuItemImagePressed
ContentImage:[UIImage imageNamed:#"Selector_Pen"]
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem4 = [[AwesomeMenuItem alloc] initWithImage:scaledImage
highlightedImage:storyMenuItemImagePressed
ContentImage:starImage
highlightedContentImage:nil];
AwesomeMenuItem *starMenuItem5 = [[AwesomeMenuItem alloc] initWithImage:scaledImage
highlightedImage:storyMenuItemImagePressed
ContentImage:[UIImage imageNamed:#"Selector_Music_Fill"]
highlightedContentImage:nil];
// the start item, similar to "add" button of Path
AwesomeMenuItem *startItem = [[AwesomeMenuItem alloc] initWithImage:[UIImage imageNamed:#"bg-addbutton.png"]
highlightedImage:[UIImage imageNamed:#"bg-addbutton-highlighted.png"]
ContentImage:[UIImage imageNamed:#"icon-plus.png"]
highlightedContentImage:[UIImage imageNamed:#"icon-plus-highlighted.png"]];
startItem.center = CGPointMake(self.tabBarController.tabBar.center.x , 30);
//22
self.menu = [[AwesomeMenu alloc] initWithFrame:CGRectMake(0, 0, 320, 568) startItem:startItem optionMenus:[NSArray arrayWithObjects:starMenuItem1, starMenuItem2, starMenuItem3, starMenuItem4, starMenuItem5,nil]];
self.menu.startPoint = CGPointMake(160.0, 22.0);
self.menu.rotateAngle = M_PI / 180 * -60;
self.menu.menuWholeAngle = M_PI / 180 * 120;
self.menu.timeOffset = 0.036f;
self.menu.farRadius = 140.0f;
self.menu.nearRadius = 110.0f;
self.menu.endRadius = 120.0f;
self.menu.delegate = self;
self.menu.hidden = YES;
[self.tabBarController.tabBar addSubview:self.menu];
[self.tabBarController.tabBar sendSubviewToBack:self.menu];
Here is how I call it from the button in the UITabBar:
[self.menu touchesBegan:nil withEvent:nil];
You have to add a UIButton into the Tabbar which triggers to initialize an empty view containing all the AwesomeMenu stuff. You can pass the touch event from the button to the awesome menu with - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event. Don't forget to dismiss the ViewController when -(void)awesomeMenuDidFinishAnimationClose:(AwesomeMenu *)menu. You also have to pass the selected MenuItems though a delegate to the parent vc.
I have added an ImageView as a subview of my TabBar (that has three NavigationControllers). When i tap on any of the tabs of the tabBarController, then the Image on the imageView changes accordingly (the image shows that particular tab selected and others unselected).
However, the image always shows an extra line on the tabBar. It looks like it crosses the limit of the tabBar. The dimensions of my image is 320x64 pixels (for non-retina iPhone) and 640x128 pixels (for retina iPhone).
Here's how i am declaring instance var for the image view and the tabBarController.
#interface HomePageViewController ()<UITabBarControllerDelegate>
{
UIImageView* tabBarView;
UITabBarController *tabBarController;
}
-(UITabBarController *) configureTheTabBarControllerWithNavControllerAtIndex:(NSInteger)index
{
UINavigationController *customerCareNavController;
UINavigationController *accAndContactsNavController;
UINavigationController *purchaseOrderNavController;
CustomerCareViewController *custCareVC;
PurchaeOrderViewController *POController;
AccountsAndContactsViewController *accAndContactsController;
custCareVC = [[CustomerCareViewController alloc] initWithNibName:#"CustomerCareViewController_iPhone" bundle:NULL];
POController = [[PurchaeOrderViewController alloc] initWithNibName:#"PurchaeOrderViewController_iPhone" bundle:NULL];
accAndContactsController = [[AccountsAndContactsViewController alloc] initWithNibName:#"AccountsAndContactsViewController_iPhone" bundle:NULL];
customerCareNavController = [[UINavigationController alloc] initWithRootViewController:custCareVC];
purchaseOrderNavController = [[UINavigationController alloc] initWithRootViewController:POController];
accAndContactsNavController = [[UINavigationController alloc] initWithRootViewController:accAndContactsController];
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:customerCareNavController,accAndContactsNavController,purchaseOrderNavController, nil];
switch (index) {
case 0:
tabBarController.selectedIndex = 0;
break;
case 1:
tabBarController.selectedIndex = 1;
break;
case 2:
tabBarController.selectedIndex = 2;
break;
}
tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, -15, 320, 64);
[tabBarController.tabBar addSubview:tabBarView];
tabBarController.delegate = self;
[self selectTabBarIndex:index];
[self presentViewController:tabBarController animated:YES completion:NULL];
return tabBarController;
}
-(void)tabBarController:(UITabBarController *)TBController didSelectViewController:(UIViewController *)viewController
{
NSUInteger indexSelected = [[TBController viewControllers] indexOfObject:viewController];
[self selectTabBarIndex:indexSelected];
}
- (void) selectTabBarIndex:(NSInteger)index
{
switch (index)
{
case 0:
tabBarView.image=[UIImage imageNamed:#"tab_myCalendar.png"];
break;
case 1:
tabBarView.image=[UIImage imageNamed:#"tab_myDetails.png"];
break;
case 2:
tabBarView.image=[UIImage imageNamed:#"TabBarItem_PO.png"];
break;
}
}
Please see the screenshot..
Setting the barStyle as black gives me the following result
The line has faded a little, but is still visible..
Hey i tried something and it works
tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, 0, 320, tabBarController.tabBar.frame.size.height);
However, the image shows a little stretched..
Write this for no stretching: This will work like a charm..!!
tabBarController.tabBar.backgroundImage = [UIImage new];
tabBarController.tabBar.shadowImage = [UIImage new];
tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, -15, 320, 64);
[tabBarController.tabBar addSubView:tabBarView];
Below code will remove line from tabbar...
if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0) {
tabbarController.tabBar.barStyle=UIBarStyleBlackOpaque;
}
Instead of adding the image in an image view as a subview, add the image as the background image of the tab bar, and make the shadow image be an empty image (the line is the shadow image).
tabBarController.tabBar.backgroundImage = [UIImage imageNamed:#"tab_mypeople.png"];
tabBarController.tabBar.shadowImage = [UIImage new];
If, for some reason, you still need to use a subview rather then a background image, you can continue to do what you have in your question, but set both the background image and the shadow image to empty images (you can't set a custom shadow image without also setting a custom background image). This will get rid of that shadow image line.
tabBarController.tabBar.backgroundImage = [UIImage new];
tabBarController.tabBar.shadowImage = [UIImage new];
tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, -15, 320, 64);
[tabBarController.tabBar addSubview:tabBarView];
write this in app delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
UIImage *tabBackground = [[UIImage imageNamed:#"tab_bg"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"tab_select_indicator"]];