iOS Facebook Like Button Not Resizing - ios

I am setting up an iOS app and have implemented a Facebook like button. Problem is, when I try to adjust the size according to their documentation found here, it just does not resize. Here's my setup code which is all the code that uses the like button:
(ViewController.h)
#property FBSDKLikeControl* likeButton;
(ViewController.m)
#synthesize likeButton;
- (void)viewDidLoad {
...
likeButton = [[FBSDKLikeControl alloc] initWithFrame:CGRectMake(20, 20, 128, 64)];
likeButton.objectID = #"https://www.facebook.com/mypage";
}
- (void)showLikeButton {
[self.view addSubview:likeButton];
}
- (void)hideLikeButton {
[likeButton removeFromSuperview];
}
When showLikeButton is called (which is after the app has been running a little while), the button shows up as expected, but no matter what size I initialize the button with, it doesn't change its size. Any ideas? Thanks in advance.

Use FBSDKLikeButton in place of FBSDKLikeControl. It inherits from UIButton and responds to sizing changes, although the image resolution suffers.

Related

UIButton subclass highlighting error (highlight remains or persists even after tap or touch down)

I subclassed UIButton in my app and there are many times when the highlight color stays even when I'm done pressing down the button. I can't figure out exactly what causes this since it only seems to happen by chance, but it seems to happen about 50% of the time. I'm very sure that this is reproducible. I often get this to happen when I have a button in a UITableViewCell and I click on it while the table view is still scrolling.
Is there something wrong with the way I'm overriding the setHighlighted method in the subclass? This is my implementation:
#implementation SCPFormButton
- (id)initWithFrame:(CGRect)frame label:(NSString *)label
{
self = [super initWithFrame:frame];
if (self) {
UILabel *buttonLabel = [[UILabel alloc] init];
buttonLabel.attributedText = [[NSAttributedString alloc] initWithString:[label uppercaseString] attributes:kButtonLabelAttributes];
[buttonLabel sizeToFit];
buttonLabel.frame = CGRectMake(kMaxWidth / 2 - buttonLabel.frame.size.width / 2, kStandardComponentHeight / 2 - buttonLabel.frame.size.height / 2, buttonLabel.frame.size.width, buttonLabel.frame.size.height);
[self addSubview:buttonLabel];
self.backgroundColor = kFormButtonColorDefault;
}
return self;
}
- (void)setHighlighted:(BOOL)highlighted
{
self.backgroundColor = highlighted ? kFormButtonColorHighlighted : kFormButtonColorDefault;
[self setNeedsDisplay];
}
#end
I would try to call super in your setHighlighted override. Indeed, Apple docs for UIControl state:
Specify YES if the control is highlighted; otherwise NO. By default, a control is not highlighted. UIControl automatically sets and clears this state automatically when a touch enters and exits during tracking and when there is a touch up.
So, it seems there is some kind of state handling going on in UIControl associated with this.
If this does not help, I would try to add a log trace so you can check which state the button is in when the touch is handled.
You are missing the call to super. But, anyway, subclassing UIButton is not recommended, I would try to do it using setBackgroundImage:forState instead.

Set Color of UIActivityIndicatorView of a UIRefreshControl?

Is there a way to set the color of the activity indicator (probably UIActivityIndicatorView) of a UIRefreshControl?
I was able to set the color of the 'rubber' and the indicator:
[_refreshControl setTintColor:[UIColor colorWithRed:0.0f/255.0f green:55.0f/255.0f blue:152.0f/255.0f alpha:1.0]];
But I want to have the 'rubber' blue and the activity indicator white, is this possible?
This is not officially supported, but if you want to risk future iOS changes breaking your code you can try this:
Building off ayoy's answer, I built a subclass of UIRefreshControl, which sets the color of the ActivityIndicator in beginRefresing. This should be a better place to put this, since you may call this in code instead of a user causing the animation to begin.
#implementation WhiteRefreshControl : UIRefreshControl
- (void)beginRefreshing
{
[super beginRefreshing];
NSArray *subviews = [[[self subviews] lastObject] subviews];
//Range check on subviews
if (subviews.count > 1)
{
id spinner = [subviews objectAtIndex:1];
//Class check on activity indicator
if ([spinner isKindOfClass:[UIActivityIndicatorView class]])
{
UIActivityIndicatorView *spinnerActivity = (UIActivityIndicatorView*)spinner;
spinnerActivity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
}
}
}
Well, you technically can do it, but it's not supported. You better follow Dave's suggestion, or read on if you insist.
If you investigate subviews of UIRefreshControl it turns out that it contains one subview, of class _UIRefreshControlDefaultContentView.
If you then check subviews of that content view in refreshing state, it contains the following:
UILabel
UIActivityIndicatorView
UIImageView
UIImageView
So technically in your callback to UIControlEventValueChanged event you can do something like this:
UIActivityIndicatorView *spinner = [[[[self.refreshControl subviews] lastObject] subviews] objectAtIndex:1];
spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
And that would work. It also doesn't violate App Review Guidelines as it doesn't use private API (browsing subviews of a view and playing with them using public API is legal).
But keep in mind that the internal implementation of UIRefreshControl can change anytime and your code may not work or even crash in later versions of iOS.
No, that's not possible. You'll need to file an enhancement request to ask Apple to implement this.

How to show overlay info view with two button more when i click a marker on google in iOS

I am trying to show a custom overlay view from the Google Maps through the Google Maps API for iOS. This overlay view content info of marker, and two my button. But I cannot find any references for this. My desired overlay view is as image with link below:
http://i1121.photobucket.com/albums/l515/dungnlh_khtn07/NguoiMoCay/overlayinfoview_zps8110b7ed.jpg
Please give me a guide for this!
Possibly, as mentioned officially in documentation of Google Maps Android API, the below restriction regarding infowindows applies to Google Maps iOs SDK also :
Info window is not a live View, rather the view is rendered as an image onto the map. As a result, any listeners you set on the view are disregarded and you cannot distinguish between click events on various parts of the view. You are advised not to place interactive components — such as buttons, checkboxes, or text inputs — within your custom info window.
So bascially clicking on any part of the infowindow will trigger only "didTapWindowOfMarker"
The best way of achieving this is to pass your GMSMapView a custom view for your info windows via the GMSMapViewDelegate's mapView:markerInfoWindow: method.
To accomplish this, set yourself up as the delegate for your GMSMapView instance, like so:
self.mapView.delegate = self;
Then return a custom UIView when requested:
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(id<GMSMarker>)marker
{
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
customView.backgroundColor = [UIColor redColor];
return customView;
}
You can find a little more information by looking in the GMSMapView header, which states:
/**
* Called when a marker is about to become selected, and provides an optional
* custom info window to use for that marker if this method returns a UIView.
* If you change this view after this method is called, those changes will not
* necessarily be reflected in the rendered version.
*
* The returned UIView must not have bounds greater than 500 points on either
* dimension. As there is only one info window shown at any time, the returned
* view may be reused between other info windows.
*
* #return The custom info window for the specified marker, or nil for default
*/
OK, but can someone please clarify how to get a UIButton on that UIView to respond to touches? Like two buttons in Dung Nguyen Le Hoang's attached picture. For example, if I add a button like this:
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(id<GMSMarker>)marker
{
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
customView.backgroundColor = [UIColor redColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[button addTarget:self action:#selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 30, 30)];
[customView addSubview:button];
return customView;
}
and of course have buttonPressed
- (void)buttonPressed
{
NSLog(#"Hello");
}
it doesn't get called. If I added the button as a subview to self.mapView then it appears on mapView, not InfoWindow and, of course, is responsive to touches. I suppose it's due to some unset frames, but can't quite get it. Can someone please clarify?
(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker
You can show AlertView or ActionSheet with two buttons when the user tap on the markerInfoContents

A UIButton above a UIPickerView

I have a UIPickerView which works correctly, now I want to add a button above it so that I can dismiss it.
and here is my code where I initiate a UIPickerView as well as its dismiss button:
- (UIPickerView *)creatPickerView {
UIPickerView *tempPickerView = [[[UIPickerView alloc]
initWithFrame:CGRectMake(kPickerViewX, kPickerViewY, kPickerViewWidth, kPickerViewHeight)] autorelease];
tempPickerView.showsSelectionIndicator = YES;
tempPickerView.delegate = self;
tempPickerView.dataSource = self;
UIButton *pickerButton = [[UIButton alloc] initWithFrame:CGRectMake(270, -32, 50, 32)];
[pickerButton setBackgroundImage:[UIImage imageNamed:#"hidePicker.png"]
forState:UIControlStateNormal];
[pickerButton addTarget:self action:#selector(hidePicker)
forControlEvents:UIControlEventTouchUpInside];
[tempPickerView addSubview:pickerButton];
[pickerButton release];
[self.view addSubview:tempPickerView];
return tempPickerView;
}
and it works well on my iPhone 4.3 Simulator, like this:
apparently there is a button on the upper right of the pickerView,
problem is, when I run the app in my device - a 5.0.1 iPhone4 and a 4.2.1 iTouch, the button is missed like it has never been added to the pickerView.
Can anyone help me with this?
Thanks a lot and a lot!
I found the reason, it seems the png has some problem,
after I change another png, it comes up in the screen!
but the real problem is that I place the button outside of the pickerView which results in the button's untouchableness.
But anyway the pickure is only a small problem.

iPhone Custom UISlider preload and rounded edges issues

I'm trying to implement a custom UISlider, I've extended it with a class called UISliderCustom which has the following code:
#implementation UISliderCustom
- (id)initWithCoder:(NSCoder *)aDecoder{
if(self == [super initWithCoder:aDecoder]){
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, 200, 13);
UIImage *slideMin = [[UIImage imageNamed:#"slideMinimum.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *slideMax = [[UIImage imageNamed:#"slideMaximum.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
[self setThumbImage:[UIImage imageNamed:#"slideThumb.png"] forState:UIControlStateNormal];
[self setThumbImage:[UIImage imageNamed:#"slideThumb.png"] forState:UIControlStateHighlighted];
[self setMinimumTrackImage:slideMin forState:UIControlStateNormal];
[self setMaximumTrackImage:slideMax forState:UIControlStateNormal];
}
return self;
}
#end
I ran into two small problems
When I slide over the slider to one of the edges (progress = 0.0 / progress = 1.0), I can clearly see "left overs" in the sides, im not sure how to handle that as well, unfortunately :)
Slider images:
Problem:
I see the regular UISlider (blue and silver) for a couple of seconds, and only then the custom graphics is loaded, or when i actually move the slider. I'm not sure why this is happening.. EDIT: This only happens in the simulator, works fine now.
Thanks in advance for any assistance :)
Shai.
You have no need to subclass UISlider to achieve this effect, and if you did you certainly wouldn't set the track images in the drawRect method. drawRect should contain drawing code only, it is called whenever any part of the control needs redrawing.
Set the thumb and track images in a separate method, either within your subclass (called from initWithFrame and initWithCoder) or in the object that creates the slider in the first place. This only needs to be done once, when the slider is first created. Don't override drawRect.
You don't need to call awakeFromNib manually either, unless you have some specific code in there as well? That would be a common place to set custom images in a subclass, if you only ever used the slider from IB.
For the square ends, the problem is that the extreme edge of your track image is square, so it is showing around the thumb. Make both ends of the track image rounded, with a 1px stretchable area in the middle, like this:
I just had a very similar problem myself. It turned out that the size (width x height) of the slider that I added in interface builder didn't match the sizes of the images I was using to customize the slider. Once I made them match, those "leftovers" at the ends of the slider went away.

Resources