I am new to i phone programming using below code i am fetching information form Facebook.
But problem is when ever if click on button it going to facebook app asking facebook user name and password after that it show same view.But here i am fetching user information but iam not able to fetch information.Its opening facebook page after that coming back to same page.Again if i click also it repeating same thing.Can any one tell how to slove this.
FBLoginView *fbLoginview = [[FBLoginView alloc] initWithPermissions:[NSArray arrayWithObject:#"publish_actions"]];
//loginview.frame = CGRectOffset(loginview.frame, 2, 2);
// loginview.frame = loginWithFbButton.frame;
fbLoginview.frame = CGRectMake(30, 10, 200, 30);
for (id obj in fbLoginview.subviews)
{
if ([obj isKindOfClass:[UIButton class]])
{
loginWithFbButton = obj;
loginWithFbButton.frame = CGRectMake(0, 0, 200, 30);
// UIImage *loginImage = [UIImage imageNamed:#"YourImg.png"];
[loginWithFbButton setBackgroundColor:[UIColor colorWithRed:69.0/255.0 green:115.0/255.0 blue:185.0/255.0 alpha:1]];
[loginWithFbButton setBackgroundImage:nil forState:UIControlStateNormal];
[loginWithFbButton setBackgroundImage:nil forState:UIControlStateSelected];
[loginWithFbButton setBackgroundImage:nil forState:UIControlStateHighlighted];
// [loginWithFbButton addTarget:self action:#selector(LoginWithFacebookk:) forControlEvents:UIControlEventTouchUpInside];
[loginWithFbButton.layer setBorderWidth:1.0f];
[loginWithFbButton.layer setBorderColor:[UIColor colorWithRed:225.0/255.0 green:227.0/255.0 blue:231.0/255.0 alpha:0.6].CGColor];
// [loginWithFbButton sizeToFit];
loginWithFbButton.layer.masksToBounds = YES;
loginWithFbButton.layer.cornerRadius = 5;
[loginWithFbButton setTitle:#" Get info from Facebook" forState:UIControlStateNormal];
[loginWithFbButton.titleLabel setFont:[UIFont fontWithName:#"HelveticaNeue" size:13]];
loginWithFbButton.titleLabel.textAlignment = NSTextAlignmentCenter;
loginWithFbButton.titleLabel.backgroundColor = [UIColor clearColor];
loginWithFbButton.titleLabel.textColor = [UIColor whiteColor];
CAGradientLayer *gradient1 = [CAGradientLayer layer];
gradient1.frame = loginWithFbButton.bounds;
UIColor *startColour1 = [UIColor colorWithRed:46.0/255.0 green:174.0/255.0 blue:225.0/255.0 alpha:1.0f];
UIColor *endColour1 = [UIColor colorWithRed:46.0/255.0 green:119.0/255.0 blue:225.0/255.0 alpha:1.0f];
gradient1.colors = [NSArray arrayWithObjects:(id)[startColour1 CGColor], (id)[endColour1 CGColor], nil];
[loginWithFbButton.layer insertSublayer:gradient1 atIndex:0];
[fbLoginview addSubview:loginWithFbButton];
}
if ([obj isKindOfClass:[UILabel class]])
{
UILabel * loginLabel = obj;
loginLabel.text = nil;
loginLabel.textAlignment = NSTextAlignmentCenter;
loginLabel.frame = CGRectMake(0, 0, 271, 26);
}
}
// fbLoginview.delegate = self;
[loginTempview3 addSubview:fbLoginview];
For fetching user information use Facebook graph API
Please have a look of this https://developers.facebook.com/docs/ios/ios-sdk-tutorial/
Make sure you have implement facebook delegate methods,
fbLoginview.delegate = self;
And implement this method to get user information
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user {
// here we use helper properties of FBGraphUser to dot-through to first_name and
// id properties of the json response from the server; alternatively we could use
NSLog(#"user :%#",user);
}
Maybe it isn't your problem! Nobody is able to post or like or comment on Facebook.. That could be the reason... Maybe it works well in a hour again!
Related
I have created a custom Facebook Login Button. Everything works but I can't get the image to center (top/bottom) in the button. The image it self is but when I create this button the image is lower.
//FB Button (Uses Facebook SDK)
self.fbLoginButton = [[FBLoginView alloc] init];
for (id loginObject in self.fbLoginButton.subviews)
{
if ([loginObject isKindOfClass:[UIButton class]])
{
UIButton * loginButton = loginObject;
UIImage *loginImage = [UIImage imageNamed:#"Facebook_White.png"];
[loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
[loginButton setBackgroundImage:nil forState:UIControlStateSelected];
[loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];
[loginButton setTitle:nil forState:UIControlStateNormal];
[loginButton setTitle:nil forState:UIControlStateSelected];
[loginButton setTitle:nil forState:UIControlStateHighlighted];
}
if ([loginObject isKindOfClass:[UILabel class]])
{
UILabel * loginLabel = loginObject;
loginLabel.text = #"";
loginLabel.frame = CGRectMake(0, 0, 0, 0);
}
}
self.fbLoginButton.delegate = self;
self.fbLoginButton.readPermissions = #[#"public_profile", #"email"];
[[self.fbLoginButton layer]setBorderWidth:2.0];
[[self.fbLoginButton layer]setBorderColor:UIColorFromRGB(0xbbffd6).CGColor];
[buttonsArray addObject:self.fbLoginButton];
Here is what it looks like compared to the Twitter Button:
Here is the actual .png (the text is white so you can't see it unless it is against a background:
Any suggestions?
After playing around, this is what worked for me. Had to hard code the fbLoginView.frame and the loginButton.frame.
//FB Button (Uses Facebook SDK)
self.fbLoginView = [[FBLoginView alloc] init];
self.fbLoginView.readPermissions = #[#"public_profile", #"email"];
self.fbLoginView.frame = CGRectMake(0, 0, 35, 35);
[[self.fbLoginView layer]setBorderWidth:2.0];
[[self.fbLoginView layer]setBorderColor:UIColorFromRGB(0xbbffd6).CGColor];
for (id loginObject in self.fbLoginView.subviews)
{
if ([loginObject isKindOfClass:[UIButton class]])
{
UIButton * loginButton = loginObject;
loginButton.frame = CGRectMake(self.fbLoginView.frame.origin.x, self.fbLoginView.frame.origin.y, 35, 35);
UIImage *loginImage = [UIImage imageNamed:#"Facebook_White.png"];
[loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
[loginButton setBackgroundImage:nil forState:UIControlStateSelected];
[loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];
}
if ([loginObject isKindOfClass:[UILabel class]])
{
UILabel * loginLabel = loginObject;
loginLabel.text = #"";
loginLabel.frame = CGRectMake(0, 0, 0, 0);
}
}
self.fbLoginView.delegate = self;
[socialButtonsArray addObject:self.fbLoginView];
I have the following code that changes the background of the Cancel button in the UISearchBar.
for( UIView *subview in self.searchBar.subviews ){
if ([subview isKindOfClass:[UIButton class]]) {
[(UIButton *)subview setEnabled:YES];
[(UIButton *)subview setTitle:#"New Button Text" forState:UIControlStateNormal];
((UIButton *)subview).tintColor = [UIColor colorWithRed:4/255.0 green:119/255.0 blue:152/255.0 alpha:1.0];
}
}
The problem is that this code does not work in iOS7! What changed in the structure of the views in the UISearchBar?
Edit: Tested here and this is the new Hierarchy of the UISearchBar:
UISearchBar:
---UIView:
------UISearchBarBackground
------UISearchBarTextField
------UINavigationButton
The problem is that i cannot test if ([sub isKindOfClass:[UINavigationButton class]]). This line throws a compile error: Use of undeclared identifier: UINavigationButton
[Edited]
Try this codes.
Add in AppDelegate if you want to change all cancel button.
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
UITextAttributeTextShadowOffset,
nil]
forState:UIControlStateNormal];
In iOS7 , we need to add objectAtIndex:0 and subviews.
The searchBar sub views hierarchy has been changed in iOS7, try the below:
in iOS7:
NSArray *searchBarSubViews = [[self.searchBar.subviews objectAtIndex:0] subviews];
iOS6 and before:
NSArray *searchBarSubViews = self.searchBar.subviews;
Solution: I created my own button. This way I can manage all the properties without having to discover what Apple did with the elements
I only have to create a UIView aux to contain the searchBar and the new Button.
self.searchBar.showsCancelButton = NO; //don`t show the original cancelButton
self.cancelSearchButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.cancelSearchButton.frame = CGRectMake(250, 6, 60, 31);
[self.cancelSearchButton setTitle:#"Cancelar" forState:UIControlStateNormal];
[self.cancelSearchButton addTarget:self action:#selector(searchBarCancelButtonClicked) forControlEvents:UIControlEventTouchUpInside];
NSString *fontName = [[self.cancelSearchButton titleLabel] font].fontName;
[[self.cancelSearchButton titleLabel] setFont:[UIFont fontWithName:fontName size:11.0]];
UIView *aux = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
aux.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1.0];
aux.layer.borderWidth = 1.0f;
aux.layer.borderColor = [UIColor lightGrayColor].CGColor;
aux.layer.cornerRadius = 0.0f;
[aux addSubview:self.searchBar];
[aux addSubview:self.cancelSearchButton];
- (void)searchBarCancelButtonClicked{
//do whatever I want to do here
}
You can take advantage of the iOS Runtime Property _cancelButton to achieve this.
UIButton *cancelButton = [self.searchBar valueForKey:#"_cancelButton"];
[cancelButton setTitleColor:[UIColor yourColor] forState:UIControlStateNormal];
For changing text
[self.searchBar setValue:#"customString" forKey:#"_cancelButtonText"];
I need to draw dynamic images on UIScrollView for this i use, MKHorizion menu (A subclass of Scroll view). Now i add Subview images on scrollview. Loop worked perfectly for adding subview on scrollview. Now in My parent class I need to touch scroll view for updated data. If i didn't touch then it is not showing updated data. Below is code
-(void) reloadData
{
[self deleteAlliTem];
self.itemCount = [dataSource numberOfImagesForMenu:self];
self.backgroundColor = [dataSource backgroundColorForImage:self];
UIFont *buttonFont = [UIFont boldSystemFontOfSize:15];
int buttonPadding = 0;
int tag = kButtonBaseTag;
int xPos = kLeftOffset;
for(int i = 0 ; i < self.itemCount; i ++)
{
NSLog(#"*************************************************************");
NSMutableDictionary *dictData=[dataSource horizMenuImage:self dictForItmeAtIndex:i];
NSString *title=[dictData valueForKey:#"name"] ? [dictData valueForKey:#"name"] : #"";
UIImage* imageItem= [UIImage imageWithData:[Base64 decode:[dictData valueForKey:#"img"]]];
int buttonWidth = 95;
UIButton *customButton = [UIButton buttonWithType:UIButtonTypeCustom];
[customButton setTitle:title forState:UIControlStateNormal];
customButton.titleLabel.font = buttonFont;
[customButton setBackgroundImage:[UIImage imageNamed:#"addFriendStrip.png"] forState:UIControlStateNormal];
[customButton setBackgroundImage:[UIImage imageNamed:#"addFriendStrip.png"] forState:UIControlStateSelected];
customButton.tag = tag++;
[customButton addTarget:self action:#selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
customButton.frame = CGRectMake(xPos, 70, buttonWidth + buttonPadding, 25);
customButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
customButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
customButton.titleEdgeInsets =UIEdgeInsetsMake(0, 10,0, 0);
customButton.titleLabel.font = [UIFont fontWithName:#"Overlock-Bold" size:16];
[customButton setTitleColor:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1] forState:UIControlStateNormal];
[customButton setTitleColor:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1] forState:UIControlStateSelected];
UIImageView* itemImageView = [[UIImageView alloc] initWithImage:imageItem];
itemImageView.tag = 200 + customButton.tag;
[itemImageView setFrame:CGRectMake(xPos, 0, buttonWidth + buttonPadding, 95)];
[self addSubview:itemImageView];
[itemImageView release];
itemImageView = nil;
[self addSubview:customButton];
xPos += buttonWidth;
xPos += buttonPadding;
if (i != self.itemCount-1){
xPos += 2.5; //5; // Richa
}
}
self.contentSize = CGSizeMake(xPos, 95);
NSLog(#"############################################################################ - %d",[[self subviews] count]);
[self scrollRectToVisible:CGRectMake(1, 0, self.frame.size.width, self.frame.size.height) animated:YES];
}
Please Help me to sort out this. Why do i needed to touch scroll view ? Do i need to override other methods ?
Did you check it is on main thread ? may be you are using GCD Queue thats why it is not updating till touch.
just try to bring your scrollview on top.I am not getting your question correctly ,but it may help.
Let me know if it is working or not..!!!
Happy Coding.!!!!
My button is not responding to touch events, please find the code snippet as below.
I have added UIButton to UIView and set the UIView to UITableView's footerview.
Please let me know and thanks.
CGRect tblViewFrame = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, 300);
self.tblViewSettings = [[[UITableView alloc]initWithFrame:tblViewFrame style:UITableViewStyleGrouped]autorelease];
self.tblViewSettings.backgroundColor = [UIColor clearColor];
self.tblViewSettings.showsVerticalScrollIndicator = FALSE;
self.tblViewSettings.delegate = self;
self.tblViewSettings.dataSource = self;
self.tblViewSettings.scrollEnabled = YES;
// Set the background color
self.view.backgroundColor = [UIColor clearColor];
UIView *buttonView = [[[UIView alloc]initWithFrame:CGRectMake(10,10, 320, 60)]autorelease];
self.signoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.signoutButton.frame = CGRectMake(10,10, 300, 40);
UIImage *image = [[UIImage imageNamed:#"btn-large1.png"] stretchableImageWithLeftCapWidth:22 topCapHeight:0];
NSString *strSignOut = NSLocalizedString(#"Sign Out", #"SignOut Button");
[self.signoutButton setTitle:strSignOut forState:UIControlStateNormal];
[self.signoutButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.signoutButton.titleLabel.shadowOffset = CGSizeMake(0, -1);
[self.signoutButton setBackgroundImage:image forState:UIControlStateNormal];
self.signoutButton.titleLabel.font = [UIFont boldSystemFontOfSize:20.0];
[self.signoutButton addTarget:self action:#selector(signOutBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
buttonView.backgroundColor = [UIColor clearColor];
[buttonView addSubview:self.signoutButton];
buttonView.userInteractionEnabled = YES;
//[self.view addSubview:buttonView];
self.tblViewSettings.tableFooterView = buttonView;
self.tblViewSettings.tableFooterView.userInteractionEnabled = YES;
[self.view addSubview:self.tblViewSettings];
-(IBAction)signOutBtnTapped:(id)sender{
}
I have looked at your code and applied it to my project. actually it works. i did not change anything from your code. i guess u must check out the frames of table view and the bottom view as everything else is working fine.
Try capturing the event for UIControlEventTouchDown instead of UIControlEventTouchUpInside in
[self.signoutButton addTarget:self action:#selector(signOutBtnTapped:) forControlEvents: UIControlEventTouchUpInside];
Everything else seems OK.
for Adding button in Footer view Section
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView* customView;
customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 60.0)];
UIButton *Login_Btn = [UIButton buttonWithType:UIButtonTypeCustom];
[Login_Btn setImage:[UIImage imageNamed:#"btn_login.png"] forState:UIControlStateNormal];
Login_Btn.frame = kiPhoneButtonFrame;
[customView addSubview:Login_Btn];
[Login_Btn addTarget:self
action:#selector(Login_Btn_Clicked:)
forControlEvents:UIControlEventTouchUpInside];
return customView;
}
And Button Click Method
-(IBAction)Login_Btn_Clicked:(id)sender
{
// Code for button CLick which you want to do.
}
i have implemented the following code in my project!
UIImage *add_item_icon = [UIImage imageNamed:#"add_item_icon.png"];
UIImage *img = [UIImage imageNamed:#"add_button.png"];
if(headerButton != nil)
[headerButton release];
headerButton = [[UIButton alloc] init];
headerButton.frame = CGRectMake(0, 0, 320, 42);
headerButton.backgroundColor = [UIColor clearColor];
headerButton.showsTouchWhenHighlighted = YES;
[headerButton setBackgroundImage:img forState:UIControlStateNormal];
[headerButton setTitle:#"Add New Gallery" forState:UIControlStateNormal];
[headerButton setImage:add_item_icon forState:UIControlStateNormal];
headerButton.titleLabel.font = [UIFont systemFontOfSize:16];
headerButton.titleLabel.textColor = [UIColor darkGrayColor];
[headerButton addTarget:self action:#selector(headerButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//[headerButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateSelected];
My question is whenever i click the button, the color which is assigned to the title has been changed. The requirement is it should not be like that. Any one pls guide me! as early possible.
Not sure what is in your -headerButtonClicked:, but you should remove anything that looks like this in -headerButtonClicked:
headerButton.titleLabel.textColor = [UIColor darkGrayColor];