I want to add medium thick black border and shadow to the buttons that I have added in my iPad application. I have taken those buttons as custom as I have applied images on them. How can I add border and shadow to ht
To add shadows and border is simple.
1) Add the QuartzCore framework to your target.
2) Import the framework header in the class where you want to add borders and shadows. (Or if you have custom class for the button then you can simple import this framework in that class.)
3) To add the border to the button use this code (where button is an IBOutlet connected with the button in interface):
[self.button.layer setBorderWidth:3.0];
[self.button.layer setBorderColor:[[UIColor blackColor] CGColor]];
4) To add the shadow to the button use the following code:
[self.button.layer setShadowOffset:CGSizeMake(5, 5)];
[self.button.layer setShadowColor:[[UIColor blackColor] CGColor]];
[self.button.layer setShadowOpacity:0.5];
You can play around with the values and see how it will affect the behaviour.
If you were in Cocoa, you could use NSView's setShadow. (NSView is an ancestor of NSButton.) I don't see the equivalent method for UIView, so I don't think there is any simple way of doing that in iOS. Come to think of it, I don't think I've seen that effect in iOS apps, period.
But since you're using custom button images anyway, why not prepare images that include shadow and border?
Related
I am new for cocoa OSX application might be this question is simple but i try my best to find out this issue and at the end i asking question here.
I am creating NSWindowViewController and in side it i Used NSTableview with Customcell. In customeCell i used NSView (customView) and all Cell IBOutlet put in side NSView. When First time that NSWindowViewController load that show fine but after close the window and again i open it. its NSTextField IBOutlet change its position top to bottom of the cell.
I try to find this some property change but did not fix it i attach its screen example what was happen with my cocoa osx Application.
I notice that this happen when i used following code for setting NSview's background color from property Inspector i setting NSView Core animation like.
And set background color in viewForTableColumn like:
cellView.bgview.layer.backgroundColor = [NSColor whiteColor].CGColor;
Color set properly and all working fine when i reload table view that top label going to bottom and that will display revers UI order for cell as i show in my question.
And i tested with if i remove NSView setting background color code as i mention above then working perfect no re-order and all things. I am not using Auto-layout.
So after then i create custom subclass of NSview for setting color like following:
- (void)drawRect:(NSRect)dirtyRect {
[[NSColor whiteColor] setFill];
NSRectFill(dirtyRect);
[super drawRect:dirtyRect];
// Drawing code here.
}
I remove my old code and use this one for setting background by creating NSView subclass and my issue fix.
I'd like to use this same solution with my UIView to get the same result.
I have a UIView with a UIScrollView. These are embedded in a UINavigationController.
A customer adds an item to their basket and I would like to give them a confirmation message. Right now a little basket UIBarButtonItem updates a title within to show the number of items. This is fine but not every user/customer will notice this.
I don't really like the style of a UIAlertView for this situation. So I'm going to add my own UIView and style it how I want to.
I'm trying to figure out how to get the UIView to show up in the center of the window. Whether the customer is using an iPhone4 or iPhone5.
UIView code:
UIView *confirmationPopup = [[UIView alloc] initWithFrame:CGRectMake(10, 200, 300, 100)];
[confirmationPopup setBackgroundColor:[UIColor redColor]];
// confirmationPopup.center = [confirmationPopup.superview convertPoint:confirmationPopup.superview.center fromView:confirmationPopup.superview.superview];
[[[self navigationController] view] addSubview:confirmationPopup];
The popup view is centered horizontally automatically but not vertically. I've tried to play around with the line you can see I've commented out but it doesn't center the UIView in the center of the window. It appears to be centering it inside the NavBar
Would appreciate some solutions.
Don't hard-code; use auto layout. You might be helped by my custom class for this purpose, an imitation alert view substitute that you can configure however you like. It takes advantage of iOS 7 custom presentation view transitions. (Of course in iOS 8 there will be even more support for this kind of thing, i.e. UIPresentationController.)
I want to mimic what seem to be the standard UI for using the UISearchBar, and right now I trying to make the rest of the view gray, when I begin searching, and I tried doing that by just setting the background color of the view to gray, but I am using sections in my UITableView, and they are not turning gray. Anybody have any reasons why that is?
The reason you're not seeing the section headers fade to gray is because they are drawn on top of the gray background, and are opaque; in other words, their alpha is 1.
If you're looking for a suggestion to get the effect you want, my first reflex would be to add an overlay UIView as a subview of the area you want to be "grayed out", and change its background color when certain events occur. Something like this:
// You have to choose what view is the one that needs to be grayed out.
// I'll call the view you want to gray out "viewToBeGrayed"
UIView *grayOverlay = [[UIView alloc] initWithFrame:viewToBeGrayed.frame];
// Initially, the overlay should be clear
[grayOverlay setBackgroundColor:[UIColor clearColor]];
[viewToBeGrayed addSubview:grayOverlay];
Then, when you want to "gray out" viewToBeGrayed, just change the background color of grayOverlay to some translucent gray value:
[grayOverlay setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.5]];
Finally, when you want to get rid of the "grayed out" effect, just set the view back to clear:
[grayOverlay setBackgroundColor:[UIColor clearColor]];
That should be a good place to start. Comment if you need any additional help.
Use the standard UISearchController for your tableview search needs.
I have a UIScrollView, with a UIImageView and UIButton inside of it.
I was reading in the answers here that if I have a single view that contains all of my zoomable content, then I should be fine. The problem is that the button doesn't zoom when the image does.
I thought that what I have would work, since the Scroll View is the zoomable view.
Do I need to create another UIView and put everything in there (and keep the same hierarchy?) ?
Have you checked your Springs and Struts? Look in the size inspector under "autosizing". Those little red lines.. if that doesn't make sense, search for 'auto layout'.
I ended up fixing this by declaring the button in code, and added a UView into the hiearchy. The uiview is a subview of the scroll view, and the imageview is a subview of the uiview. I then added the buttons to the uiview.
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
...
[view addSubview:button];
i have a tableview and i wish to customize accessoryview button.
For that i have custom PNG image with semi-transparent pixels.
UIButton *myAccessoryButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
[myAccessoryButton setUserInteractionEnabled:YES];
[myAccessoryButton setBackgroundColor:[UIColor clearColor]];
[myAccessoryButton setImage:[UIImage imageNamed:#"accessory_btn"] forState:UIControlStateNormal];
[myAccessoryButton addTarget: self
action: #selector(accessoryButtonTapped:withEvent:)
forControlEvents: UIControlEventTouchUpInside];
[cell setAccessoryView:myAccessoryButton];
And that works fine for me button draws, except one trouble. In my template (PSD) this button has blend mode - overlap, and when i export that button from PSD format it have white semi-transparent pixels which must blends with table background in same overlap blend-mode. But by default exported PNG blends in default mode when i load it as UIImage to customize my accessoryview.
How to change blend mode of UIImage or UIButton or AccessoryView may be?
Is the picture on the left what you get in Photoshop? You want it to brighten the background without altering its hue? If so, there's no easy way to achieve that.
There are two partial solutions:
Have a single drawRect block (or its CALayer equivalent) which draws the background and the draws the glow using the appropriate CGBlendMode.
Edit the picture so the glow at the bottom is the shade of brown of your current background.
Either way, you lose flexibility; it would be nice to drag around your buttons or change the background graphic and have everything merge together nicely.
This may change. CALayer already has a property called compositingFilter. However, as of iOS 5.1, its behavior is undefined. If anyone reads this in a future where iOS does have compositing filter that work, please add a comment to say so.