problem in adding second UIbutton in cameraOverlayView - iphone

problem in adding second UIbutton in cameraOverlayView ,here i am able to add the first button but not able to add second button with following code
- (void)pickAndDecodeFromSource:(UIImagePickerControllerSourceType) sourceType {
[self reset];
// Create the Image Picker
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
UIImagePickerController* aPicker =
[[[UIImagePickerController alloc] init] autorelease];
aPicker.sourceType = sourceType;
aPicker.delegate = self;
self.picker = aPicker;
// [[NSUserDefaults standardUserDefaults] boolForKey:#"allowEditing"];
BOOL isCamera = (sourceType == UIImagePickerControllerSourceTypeCamera);
if ([picker respondsToSelector:#selector(setAllowsEditing:)]) {
// not in 3.0
[picker setAllowsEditing:!isCamera];
}
if (isCamera) {
if ([picker respondsToSelector:#selector(setShowsCameraControls:)]) {
[picker setShowsCameraControls:NO];
UIButton *cancelButton =
[UIButton buttonWithType:UIButtonTypeRoundedRect];
NSString *cancelString =
NSLocalizedString(#"DecoderViewController cancel button title", #"");
CGFloat height = [UIFont systemFontSize];
CGSize size =
[cancelString sizeWithFont:[UIFont systemFontOfSize:height]];
[cancelButton setTitle:cancelString forState:UIControlStateNormal];
//cancelButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"CancelButtonForButton.png"]];
//cancelButton.backgroundColor = [UIColor clearColor];
//cancelButton.backgroundColor = [UIColor greenColor];
[cancelButton setImage:[UIImage imageNamed:#"cancelForButton.png"] forState:UIControlStateNormal];
//[cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
CGRect appFrame = [[UIScreen mainScreen] bounds];
static const int kMargin = 10;
static const int kInternalXMargin = 10;
static const int kInternalYMargin = 10;
CGRect frame = CGRectMake(kMargin,
appFrame.size.height - (height + 2*kInternalYMargin + kMargin),
2*kInternalXMargin + size.width,
height + 2*kInternalYMargin);
[cancelButton setFrame:frame];
[cancelButton addTarget:self
action:#selector(cancel:)
forControlEvents:UIControlEventTouchUpInside];
picker.cameraOverlayView = cancelButton;
// The camera takes quite a while to start up. Hence the 2 second delay.
[self performSelector:#selector(takeScreenshot)
withObject:nil
afterDelay:2.0];
//cancelButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg.png"]];
}
}
// Picker is displayed asynchronously.
[self presentModalViewController:picker animated:YES];
} else {
NSLog(#"Attempted to pick an image with illegal source type '%d'", sourceType);
}
}

The issue is that you are replacing the camera overlay with the first button - so creating the second button and using "picker.cameraOverlayView = newButton;" replaces the camera-overlay again.
The solution is to create a parent UIView, add both buttons to it, and then set the camera overlay to be the parent UIView.

Related

Trouble Setting Button Image When On a ScrollView

I'm making an app. My app is based off this sample project. https://github.com/yeahdongcn/RSCircaPageControl
In the app there is a view. On the view, there is a scroll view (UIScrollView *scrollView) which allows to 10 "pages" of content. Within each page, there is another scroll view (UIScrollView *sv) which is a subview of *scrollView.
On SV, I then added a button called UIButton *button. When I attempt to change the button's images after a time of "two minutes," nothing happens. This is because there are 10 buttons. I need to change the image of the button on only one of the pages. Not all of them.
Something tells me it needs "object at index" or something to specify which button on which page I want to change.
The code is below! Thanks guys!
- (void)viewDidLoad
{
[super viewDidLoad];
self.clipView = [[RSView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
self.clipView.clipsToBounds = YES;
[self.view addSubview:self.clipView];
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.clipView.bounds.size.width, kScrollViewHeight)];
self.scrollView.delegate = self;
self.scrollView.clipsToBounds = NO;
self.scrollView.pagingEnabled = YES;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.showsVerticalScrollIndicator = NO;
self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:self.scrollView];
self.clipView.scrollView = self.scrollView;
self.pageControl = [[RSCircaPageControl alloc] initWithNumberOfPages:10];
CGRect frame = self.pageControl.frame;
frame.origin.x = self.view.bounds.size.width - frame.size.width - 10;
frame.origin.y = roundf((self.view.bounds.size.height - frame.size.height) / 2.);
self.pageControl.frame = frame;
self.pageControl.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[self.pageControl setCurrentPage:0 usingScroller:NO];
[self.view addSubview:self.pageControl];
CGFloat currentY = 0;
for (int i = 0; i < 10; i++) {
UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(0, currentY, self.scrollView.bounds.size.width, kScrollViewHeight)];
sv.tag = kScrollViewTagBase + i;
sv.delegate = self;
sv.autoresizingMask = UIViewAutoresizingFlexibleWidth;
sv.backgroundColor = [UIColor colorWithRed:(arc4random() % 257) / 256. green:(arc4random() % 257) / 256. blue:(arc4random() % 257) / 256. alpha:1];
///here's the buttton!!
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage*normal = [UIImage imageNamed:#"girl.jpg"];
UIImage*selected = [UIImage imageNamed:#"girl2.jpg"];
button.frame = CGRectMake(100, 100, 50,50));
[button setImage:normal forState:UIControlStateNormal];
[button setImage:selected forState:UIControlStateHighlighted];
button.contentMode = UIViewContentModeScaleAspectFit;
[button addTarget:self
action:#selector(myButtonPressed:)
forControlEvents:UIControlEventTouchDown];
[sv addSubview:button]; //notice that the button is added as a subview of SV
[self.scrollView addSubview:sv]; // notice that SV is a subview of the scrollView.
if (i == 2 || i == 6) {
sv.contentSize = CGSizeMake(sv.contentSize.width, kScrollViewContentHeight);
}
currentY += kScrollViewHeight;
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.contentSize.width, currentY);
[self performSelector:changeButtomImages withObject:nil afterDelay:TwoMinutes];
}
- (void)changeButtonImages {
UIImage*normal2 = [UIImage imageNamed:#"boy.jpg"];
UIImage*selected2 = [UIImage imageNamed:#"boy2.jpg"];
[button setImage:normal2 forState:UIControlStateNormal];
[button setImage:selected2 forState:UIControlStateHighlighted];
}
Kyle
for setting button image in a normal state the parameter to pass forState: is UIControlStateNormal not UIControlStateHighlighted
So, in changeButtonImages you are changing the the image for the iVar "button", but you are never actually assigning anything to that button var. In your for loop in viewDidLoad, you are creating a local variable of UIButton called button. Maybe something like this?
- (void)myButtonPressed:(id)sender
{
UIButton *button = (UIButton *)sender;
UIImage*normal2 = [UIImage imageNamed:#"boy.jpg"];
UIImage*selected2 = [UIImage imageNamed:#"boy2.jpg"];
[button setImage:normal2 forState:UIControlStateNormal];
[button setImage:selected2 forState:UIControlStateHighlighted];
}

UIImagePickerController does not show edit screen

I'm playing around with a cameraOverLayView and encountered a weird behavior. Before presenting the UIImagePickerController, I set allowsEditing to YES. After the capture screen comes up, I tap on a button that triggers takePicture(). Instead of presenting the editing screen, the delegate method didFinishPickingMediaWithInfo() gets called right away. Can anyone help me figure out what I could be doing wrong? I pasted some of my code below...
Thanks!
- (BOOL)shouldStartCameraController {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO) {
return NO;
}
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
float overlayOffset = 0;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if (screenSize.height > 480.0f) {
overlayOffset = 195;
} else {
overlayOffset = 103;
}
} else {
/*Do iPad stuff here.*/
}
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]
&& [[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera] containsObject:(NSString *)kUTTypeImage]) {
cameraUI.mediaTypes = [NSArray arrayWithObject:(NSString *) kUTTypeImage];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
cameraUI.cameraDevice = UIImagePickerControllerCameraDeviceRear;
} else if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
cameraUI.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
} else {
return NO;
}
UIView *cameraOverlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cameraUI.view.frame.size.width, cameraUI.view.frame.size.height)];
UIImageView *cameraOverlayImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"iphone5_camera_overlay.png"]];
cameraOverlayImageView.frame = CGRectMake(0, 0, cameraUI.view.frame.size.width, cameraUI.view.frame.size.height);
[cameraOverlayView addSubview:cameraOverlayImageView];
UILabel *cameraLabel = [[UILabel alloc] initWithFrame:CGRectMake( 0.0f, self.view.bounds.size.height-overlayOffset, self.view.bounds.size.width, 50.0f)];
[cameraLabel setTextAlignment:NSTextAlignmentCenter];
[cameraLabel setBackgroundColor:[UIColor clearColor]];
[cameraLabel setTextColor:[UIColor whiteColor]];
[cameraLabel setShadowColor:[UIColor colorWithWhite:0.0f alpha:0.300f]];
[cameraLabel setShadowOffset:CGSizeMake( 0.0f, -1.0f)];
[cameraLabel setFont:[UIFont boldSystemFontOfSize:18.0f]];
[cameraOverlayView addSubview:cameraLabel];
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cancelButton addTarget:self action:#selector(cancelButtonPressed:) forControlEvents:UIControlEventTouchDown];
[cancelButton setFrame:CGRectMake(10, cameraOverlayView.frame.size.height-60, 50, 50)];
[cancelButton setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5f]];
[cameraOverlayView addSubview:cancelButton];
UIButton *snapButton = [UIButton buttonWithType:UIButtonTypeCustom];
[snapButton addTarget:self action:#selector(takePictureButtonPressed:) forControlEvents:UIControlEventTouchDown];
[snapButton setFrame:CGRectMake(110, cameraOverlayView.frame.size.height-60, 100, 50)];
[snapButton setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5f]];
[cameraOverlayView addSubview:snapButton];
cameraUI.allowsEditing = YES;
cameraUI.showsCameraControls = NO;
cameraUI.delegate = self;
self.imagePickerController = cameraUI;
[self presentModalViewController:cameraUI animated:YES];
return YES;
}
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer {
[self shouldPresentPhotoCaptureController];
}
#pragma mark - UIBarButton Selectors
- (void)takePictureButtonPressed:(id)sender {
NSLog(#"takePictureButtonPressed...");
// TODO: take picture!
[self.imagePickerController takePicture];
}
Possible dublicate: How do I use [camera takePhoto] and edit using UIImagePicker - UIImagePickerController.allowsEditing = YES
According to takePicture: method in Apple documentation:
Use this method in conjunction with a custom overlay view to initiate the programmatic capture of a still image. This supports taking more than one picture without leaving the interface, but requires that you hide the default image picker controls.
Calling this method while an image is being captured has no effect. You must wait until the associated delegate object receives an imagePickerController:didFinishPickingMediaWithInfo: message before you can capture another picture.
It seems that this approach (custom overlay) it is configured in order to be managed by yourself. Even if "allowsEditing = YES" the taken picture will be directly sent to imagePickerController:didFinishPickingMediaWithInfo:.
Based on that if we want to edit the taken picture using our custom user interface we should create an according custom edit screen for that purpose.

UIButton selector not working on mainwindow view

I am adding a custom view on main window then on the view i am creating a button and button is showing but the action is not performing on button tapped.
on a button tap i want to open a photogallery.
and in a loop the buttons are created.
code that i am using is there...
UIImage *image=[[UIImage alloc] initWithData:data cache:NO];
UIImageView *iv=[[UIImageView alloc] initWithFrame:CGRectMake(200, y, 75, 75)];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(200, y, 75, 75)];
[button setAlpha:0];
[button setTag:i];//change this to your loop counter
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
iv.image=image;
// iv.tag=#"bigimage.jpg";
iv.userInteractionEnabled=YES;
button.userInteractionEnabled = YES;
[iv addSubview:button];
[button release];
y=y+145;
[view1 addSubview:iv];
[iv release];
And also try this code but no improvements are there.....
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(200, y, 75, 75);
UIImage *img = [[UIImage alloc] initWithData:data];
[button setBackgroundImage:img forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
y = y+145;
[view1 addSubview:button];
The frame of your button should not have the same origin x and y as your imageview. If you want it inside the image view it should have origin x:0 y:0 and the same width and height as your imageview.
The origin x,y is relative to it's parent. In your case the imageview.
Hello Shivangi,
I think you want to set image on button so try this code its will help you
//function to create button dynamically on scrollview
-(void)createButton
{
int Y = 20;
indexRow = 0;
for (int i = 0; i < [prow.noOfPhotos count]; i++)
{
thumbNailButton = [UIButton buttonWithType:UIButtonTypeCustom];
int X = 4 + (78 * (i % 4));
NSLog(#"X = %d",X);
NSLog(#"Start Y = %d",Y);
if (i % 4 == 0)
{
NSLog(#"%d",i);
Y = (70 * verticalImageRowCount);
NSLog(#"Y = %d",Y);
verticalImageRowCount++;
NSLog(#"VerticalImageRowCount= %d");
}
CGRect rect = myScrollView.frame;
rect.size.width = 100;
rect.size.height = Y + 77;
myScrollView.contentSize = CGSizeMake(rect.size.width,rect.size.height);
thumbNailButton.frame = CGRectMake(X,Y, 62,65);
view = [[UIImageView alloc] init];
prow.photo = [prow.noOfPhotos objectAtIndex:indexRow];
imagePath = prow.photo;
asyncImageView = [[[AsyncImageView alloc] initWithFrame:CGRectMake(4, 0, 62, 65)] autorelease];
asyncImageView.backgroundColor = [UIColor clearColor];
[view addSubview:asyncImageView];
NSURL *url = [NSURL URLWithString:imagePath];
[asyncImageView loadImageFromURL:url];
[view setImage:[UIImage imageNamed:[prow.noOfPhotos objectAtIndex:i]]];
thumbNailButton.tag = i;
thumbNailButton.backgroundColor=[UIColor clearColor];
[thumbNailButton addTarget:self action:#selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
[thumbNailButton addSubview:view];
[myScrollView addSubview:thumbNailButton];
indexRow+= 1;
}
}
Try putting an NSLog in your buttonPressed: and see if that method is getting called. Maybe the method is getting called but the Photo Gallery app isn't launching for some other reason.
The user cannot click the button if you set the button's alpha to 0. This means the event will not be fired.
[button setAlpha:0];
This has the same effect as setting button.hidden = YES.
If you want an invisible clickzone using the button, set the button type to UIButtonTypeCustom and it should do the trick.

Thumbnail grid of images

How does one create a dynamic thumbnail grid?
How is a grid created with thumbnails of images like the photo app on iphone?
How are these spaces arranged dynamically? e.g. adding and removing thumbnails.
this is my simple grid view app
- (void)viewDidAppear:(BOOL)animated {
[[Grid_ViewAppDelegate sharedAppDelegate] hideLoadingView];
temp = temp+1;
if (temp ==1){
NSLog(#"temp:%d",temp);
int n = 20; //Numbers of array;
NSArray *t = [[NSArray alloc] initWithObjects:#"calpie.gif",#"chrysler_electric.png",#"chrysler_fiat_cap.gif",#"cleanup.gif",#"ecylindri.gif",#"elect08.png",#"globe.gif",#"heat.gif",#"insur.gif"
,#"jobs.gif",#"office.gif",#"opec1.gif",#"orng_cap.gif",#"poll.gif",#"pollen.gif",#"purbar.gif",#"robinson.gif",#"robslink_cap.gif",#"scot_cap.gif",#"shoes.gif",nil];
myScrollView.contentSize = CGSizeMake(320, 460+n*2);
myScrollView.maximumZoomScale = 4.0;
myScrollView.minimumZoomScale = 1;
myScrollView.clipsToBounds = YES;
myScrollView.delegate = self;
NSString *mxiURL = #"http://meta-x.com/biflash/images/";
int i =0,i1=0;
while(i<n){
int yy = 4 +i1*79;
for(int j=0; j<4;j++){
if (i>=n) break;
CGRect rect;
rect = CGRectMake(4+79*j, yy, 75, 75);
UIButton *button=[[UIButton alloc] initWithFrame:rect];
[button setFrame:rect];
NSString *nn = [mxiURL stringByAppendingString:[t objectAtIndex:i]];
UIImage *buttonImageNormal=[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: nn]]];
[button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
button.tag =i;
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside ];
//[self.view addSubview:button];
[myScrollView addSubview:button];
//[buttonImageNormal release];
[button release];
i++;
//
}
i1 = i1+1;
//i=i+4;
}
}
}
in AppDelegate
+ (Grid_ViewAppDelegate *)sharedAppDelegate
{
return (Grid_ViewAppDelegate *)[UIApplication sharedApplication].delegate;
}
- (void)showLoadingView
{
if (loadingView == nil)
{
loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
loadingView.opaque = NO;
loadingView.backgroundColor = [UIColor grayColor];
loadingView.alpha = 0.5;
UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(142.0, 222.0, 37.0, 37.0)];
[spinningWheel startAnimating];
spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[loadingView addSubview:spinningWheel];
[spinningWheel release];
CGRect label = CGRectMake(142.0f, 255.0f, 71.0f, 20.0f);
lblLoading = [[UILabel alloc] initWithFrame:label];
lblLoading.textColor = [UIColor whiteColor];
lblLoading.font = [UIFont boldSystemFontOfSize:14];
// UILabel
lblLoading.backgroundColor =[UIColor clearColor];
[lblLoading setText:#"Loading..."];
//[lblLoading setTextAlignment:UITextAlignmentCenter];
[loadingView addSubview:lblLoading];
}
[window addSubview:loadingView];
}
- (void)hideLoadingView
{
[loadingView removeFromSuperview];
}
definitely if u apply this logic. u get succeed

Changing the content of the UIScrollView iPhone

I am trying to create a scrollable menu bar (which I am succeeding in doing) but now instead I want to add a large button with an image centred in the button, instead of taking up the total width and height of the button
THis is my current code:
[scrollView setBackgroundColor:[UIColor whiteColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
UIImage *image;
UIImageView *iv;
UIButton *button;
count = [returned count];
for (int i=0; i<count; i++)
{
image = [UIImage imageNamed:#"coat2.jpg"];
iv = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,105,120)];
button = [[UIButton alloc] initWithFrame:CGRectMake(0,0,105,120)];
[button setAlpha:100];
[button setTag:1];
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
iv.image = image;
iv.tag=#"coat2.jpg";
iv.userInteractionEnabled = YES;
[iv insertSubview:button atIndex:0];
[button release];
[scrollView addSubview:iv];
[iv release];
}
[scrollView setScrollEnabled:YES];
[self layoutScrollImages];
scrollView.delegate = self;
the above code creates an image and button over it where the button and image are of the exact same width and height. I want the button to be significantly larger both in height and width.
Is this possible?
Thanks!
2nd attempt (using help from Joseph Tura)
[scrollView setBackgroundColor:[UIColor whiteColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
UIImage *image;
count = [returned count];
for (int i=0; i<count; i++)
{
image = [UIImage imageNamed:#"coat2.jpg"];
iv = [[UIImageView alloc] initWithFrame:CGRectMake(0,20,105,120)];
button = [[ProductButton alloc] initWithFrame:CGRectMake(0,20,105,120)];
[button setAlpha:100];
[button setTag:1];
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
iv.tag=tag;
iv.userInteractionEnabled = YES;
iv.image = myimage;
UIView *uiView = [[UIView alloc] initWithFrame:CGRectMake(0,20,105,120)];
[uiView addSubview:iv];
button = [[ProductButton alloc] initWithFrame:CGRectMake(0,0,210,240)];
button.center = CGPointMake(uiView.frame.size.width /2, uiView.frame.size.height/2);
[button setTag:1];
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[uiView addSubview:button];
[scrollView addSubview:uiView];
}
[scrollView setScrollEnabled:YES];
[self layoutScrollImages];
scrollView.delegate = self;
-----
-(void)layoutScrollImages
{
//UIImageView *view = nil;
UIView *view = nil;
NSArray *subviews = [scrollView subviews];
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += 110;
}
}
[scrollView setContentSize: CGSizeMake(count*110, [scrollView bounds].size.height)];
}
Why not put both elements inside a UIView?
UIView *aView = [[UIView alloc] initWithFrame:iv.frame];
[aView addSubview:iv];
button = [[UIButton alloc] initWithFrame:CGRectMake(0,0,210,240)];
button.center = CGPointMake(aView.frame.size.width / 2, aView.frame.size.height / 2);
[aView addSubview:button];