I have a custom UIButton like this:
_facebookButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_facebookButton addTarget:self
action:#selector(buttonFacebookPressed:)
forControlEvents:UIControlEventTouchDown];
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
[_facebookButton setBackgroundImage:[UIImage imageNamed:#"facebookInactive"] forState:UIControlStateNormal];
} else {
[_facebookButton setBackgroundImage:[UIImage imageNamed:#"facebookInactive"] forState:UIControlStateNormal];
}
_facebookButton.frame = CGRectMake(0.0, 0.0, 33.0, 33.0);
_facebookButton.center = CGPointMake(60, 48);
_facebookButton.alpha = 0;
[_subView addSubview:_facebookButton];
It is in a UITableViewCell and on the simulator it looks OK, but on the actual device it is gone. I've searched the internet and they are always talking about image names which are not correct. I use the xcasset and have an image set named: facebookInactive.
Why is the button not showing up on the device?
Thanks in advance!
Are you sure about that,
ios Setting -> Facebook -> Sign in Process is completely registered ?
this may helpful to you.
Thanks & Regards,
Rushik Thumar.
You need to remove the statement
_facebookButton.alpha = 0;
or replace it with
_facebookButton.alpha = 1.0;
you can goto your project in Project Navigator then
select your Project -> Build Phases -> Copy Bundle resourses and check that their is ".xcasset" avilable.
if No then click on "+" icon & add ".xcasset"
Now build & Run.
Related
I am developing one application.In that i am doing comparision operation for two images like below
UIImage *actual_image=usrcheck_image.image;
NSData *present_image = UIImagePNGRepresentation(actual_image);
NSData *compare_image = UIImagePNGRepresentation([UIImage imageNamed:#"unchk-1.png"]);
if([present_image isEqualToData:compare_image])
{
set the checked image
}
else
{
set the uncheck image.
}
If i run this,check image is changed to uncheck.But uncheck image is not chneged to check image.Everytime else block is executed.So please help me how to compare these two images.This code is working perfectly in device.But the problem is in simulator only.
Try This Code -
Take 2 images of checked and unchecked and assign that images to UIButton.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 160, 30);
[button setImage:[UIImage imageNamed:#"checkedImage.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:#"uncheckedImage.png"] forState:UIControlStateSelected];
button.tag = 1;
[button addTarget:self action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
And In buttonAction function -
selectedBtn.selected = NO;
button.selected = YES;
selectedBtn = button;
In .h file just mention
UIButton *selectedBtn;
Hope It may help you.
You can use highlighted property of UIImageView. Set the checked image as highlightedImage property, and on the click event set:
yourImageView.isHighlighed = !yourImageView.isHighlighed;
it will automatically show your image as toggle
May be link below can help you
Objective-C: Comparing an image against another image that has been previously saved
Let me know if this works
First thing is, there is no need of comparison of image Data and no need to compare images too,
But if you want to compare images means , just simply do like following
if(usrcheck_image.image==[UIImage imageNamed:#"unchk-1.png"]) {
usrcheck_image.image=[UIImage imageNamed:#"chk-1.png"];
} else {
usrcheck_image.image=[UIImage imageNamed:#"unchk-1.png"];
}
something strange happened during the development of my app. I have a view with several UIButtons in it. All are using custom artwork and are UIButton with CostumType.
For me everything felt right. In the simulator and on the phone.
But when I give the app in someone else's hand the person taps on a button and it won't work. It feels like the button is just reaction to a certain tap which in fact doesn't feel right (if you compare it to normal behavior).
What can I do to make it behave normal? Normal means that somebody who is used to iOS Apps can use it like he except it works.
Here is an example code for a button:
focusButton = [UIButton buttonWithType:UIButtonTypeCustom];
[focusButton setFrame:CGRectMake(self.bounds.size.width-(self.bounds.size.width/widthFactor)+108, self.bounds.origin.y+(self.bounds.size.height/(heightFactor*2))+2, 36, 40)];
focusButton.contentHorizontalAlignment = false; // I think these lines doesn't effect the behavior
focusButton.contentVerticalAlignment = false;
[focusButton setBackgroundImage:[UIImage imageNamed:#"arrowUp.png"] forState:UIControlStateNormal];
[focusButton setBackgroundImage:[UIImage imageNamed:#"arrowUpH.png"] forState:UIControlStateHighlighted];
[focusButton addTarget:self action:#selector(focusOrDefocusCourse) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:focusButton];
The Button Background looks like this:
this is woking fine.. Once just test with the frame..
UIButton *btn_foucs = [UIButton buttonWithType:UIButtonTypeCustom];
[btn_foucs setFrame:CGRectMake(20, 20, 200, 40)];
[btn_foucs setImage:[UIImage imageNamed:#"btn_erase.png"] forState:UIControlStateNormal];
[btn_foucs setImage:[UIImage imageNamed:#"btn_erase_h.png"] forState:UIControlStateHighlighted];
[self.view addSubview:btn_foucs];
You may like to take a look at the UIButton property imageEdgeInsets. This allows you to make the image draw into only part of the frame, so that the touchable area is bigger than the image itself (reducing the chance of 'missing' the button). You could do the following, for example:
int touch_offset = 10;
[focusButton setFrame:CGRectMake(self.bounds.size.width-(self.bounds.size.width/widthFactor)+108-touch_offset, self.bounds.origin.y+(self.bounds.size.height/(heightFactor*2))+2-touch_offset, 36+(touch_offset*2), 40+(touch_offset*2))];
focusButton.imageEdgeInsets = UIEdgeInsetsMake(touch_offset, touch_offset, touch_offset, touch_offset);
This should make the touchable area 10 pixels wider than the image on each side, adjustable by changing the touch_offset value. As a general guideline, Apple recommend using touchable areas no smaller than 44x44 pixels.
I am developing a Universal app, and there is a UIButton in it which works fine with iPhone but when I click it in iPad it requires many click attempts to get the touch event occur.
e.g. after 5-6 clicks it executes click event.
Below is UIButton code. Please help.
UIView *footer = [[[UIView alloc] initWithFrame:(CGRectMake(0, 0, self.tableView.frame.size.width, 54))] autorelease];
float buttonWidth = (int)((self.tableView.frame.size.width - 12 - 12) / 3);
float buttonHeight = 44;
if (clientState.Devicetype == 1) // 1=Ipad
buttonHeight = 90;
cash = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
cash.frame = CGRectMake(6, 10, buttonWidth, buttonHeight);
[cash setTitle:#"Cash" forState:UIControlStateNormal];
[cash setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
[cash addTarget:self action:#selector(handleCash:) forControlEvents:UIControlEventTouchUpInside];
cash.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
if (clientState.Devicetype == 1) // 1=Ipad
{
cash.titleLabel.font = [UIFont systemFontOfSize:28];
}
[footer addSubview:cash];
self.tableView.tableFooterView = footer;
You should check to make sure that your buttons are the correct size:
[cash sizeToFit]
I've experienced that if some other view is blocking it (and you click on that part of your button it won't fire off the event) it will take several clicks because you eventually press the button where it's not being covered. So make sure no other frame/bounds is over the top of your button and make sure your button is sized correctly.
I agree with #Inturbidus that it's probably another transparent view covering part of the button. I find the best way to troubleshoot this is to change the background color on all my other views (scrollviews, etc) to make sure they are behaving like I think they are. Sometimes it will surprise you when you see where they are actually positioned with background color turned on.
I have a button in headerview of my tableview, its woking fine as well, but problem i am having is: When I want to hide that button on click of another button. How can I achieve this? I have already tried
[deletebutton removeFromSuperview];
where deleteButton is my buttons name.
Here is what I am doing
-(void)PutTableinEditMode{
DeleteButton=[UIButton buttonWithType:UIButtonTypeCustom];
DeleteButton.frame=CGRectMake(10,1, 65, 25);
[DeleteButton setTitle:#"Delete" forState:UIControlStateNormal];
DeleteButton.backgroundColor=[UIColor clearColor];
[DeleteButton addTarget:self action:#selector(DeleteMultipleToDos) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:DeleteButton];
}
Then I m having another function as below from where i want to hide this DeleteButton
-(void)DoneEditing
{
DeleteButton.hidden=YES;
[DeleteButton removeFromSuperview];
}
deletebutton.hidden = YES
if any of those two solution (removeFromSuperview and hidden) do not work, then you certainly don't have the right reference to your button. I guess your using nib files to define your views ? Then be sure the member deleteButton is well "linked" to the actual button. (i.e. verify using debug that your deleteButton var is not null)
Can u try and change the Text of that button because i'm thinking your sending messages to nil objects.
I got the it working actually [DeleteButton removeFromSuperView] is working .. problem was that the first method PutTableinEditMode was being called from somewhere else also, so i simply took a bool variable and on basis of its value added and removed the delete button
:)
Thanks guys for helping though :)
Ifeel so stupid to make such a silly mistake :)
Is there a way to get access to the up/down arrows used in the Mail app and implement them the same way?
No, there's no supported way to do it. I'd suggest you file a bug on Radar asking Apple to include more built-in artwork. In the mean time, you'll just have to draw your own.
Can you clarify your question?
The graphics for up/down are not easily accessible, though you can probably find a way to get them. For instance, see http://0xced.blogspot.com/2009/04/extract-uikit-artwork.html.
But if you're looking for the behavior, it's really quite simple. The arrows are on a momentary UISegmentedControl. Attach to valueChanged: to tell when the user taps on one of them, and use selectedSegmentIndex to tell which one they tapped.
Nowadays they are part of the sample code of IOS 4.1. Check the NavBar sample.
As Steven Fisher said, you can’t access the Apple graphic easily. But they are relatively easy to remake.
Given the images I had some trouble making this look right in iOS 7 where a UISegmentedControl will not work. This code did the trick however (added to viewDidLoad in the ViewController).
UIButton *upButton = [UIButton buttonWithType:UIButtonTypeCustom];
[upButton setImage:[upImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
forState:UIControlStateNormal];
upButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 6);
[upButton sizeToFit];
UIButton *downButton = [UIButton buttonWithType:UIButtonTypeCustom];
[downButton setImage:[downImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
forState:UIControlStateNormal];
downButton.contentEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
[downButton sizeToFit];
UIBarButtonItem *upButtonItem = [[UIBarButtonItem alloc] initWithCustomView:upButton];
UIBarButtonItem *downButtonItem = [[UIBarButtonItem alloc] initWithCustomView:downButton];
[upButton addTarget:self action:#selector(YOUR_UP_SELECTOR:) forControlEvents:UIControlEventTouchUpInside];
[downButton addTarget:self action:#selector(YOUR_DOWN_SELECTOR:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItems = #[downButtonItem, upButtonItem];