UIAlertview Button columns - iphone

In iphone application can we set number of columns in UIAlertView as if I have six buttons in UIAlertView then how can I show it in 2 columns and 3 rows. If any one done it kindly share it how it will done ..
Any sample code will be extra help

A UIAlertView is just a UIView. So you can manually add the buttons to the UIAlertView in a two column configuration. There is an example here that demonstrates adding UITextFields, but I'm sure you can adapt it.
Note that having two many buttons in the UIAlertView might get Apple's back up ;-)

I have done it like this
NSArray *subViewArray = Topicdialog.subviews;
float y = 60.0f;
for(int x=2;x<[subViewArray count];x += 2){
UIView *button = [subViewArray objectAtIndex:x];
CGRect frame = button.frame;
frame.size.width = 120.0f;
frame.size.height = 42.0f;
frame.origin.x = 20.0f;
frame.origin.y = y;
button.frame = frame;
UIView *button1 = [subViewArray objectAtIndex:x + 1];
frame = button1.frame;
frame.size.width = 120.0f;
frame.size.height = 42.0f;
frame.origin.x = 152.0f;
frame.origin.y = y;
button1.frame = frame;
y = y + 48.0f;
}

Related

UITableview not placed correctly in uiscrollview

I have a UIscrollView that uses a pagecontrol. I'm adding tables to the scrollview in code. The tableviews should have a padding of 20px on each side. So I do the following.
CGRect frame = self.scrollView.bounds;
frame.size.width = 280.0f;
frame.size.height = self.scrollView.bounds.size.height;
frame.origin.x = (320 * page)+20;
NSLog(#"orgin x is %d",(320 * page)+20);
NSLog(#"orgin x is %f",frame.origin.x);
frame.origin.y = 0;
UITableView *tableStage = [[UITableView alloc]initWithFrame:frame];
tableStage.backgroundColor = [UIColor colorWithRed:(250/255.0) green:(248/255.0) blue:(247/255.0) alpha:100];
tableStage.delegate = self;
tableStage.dataSource = self;
tableStage.tag = page;
tableStage.contentMode = UIViewContentModeScaleAspectFit;
[self.scrollView addSubview:tableStage];
[self.pageViews replaceObjectAtIndex:page withObject:tableStage];
But I'm getting the following result.
Like you can see the next tableview is always moving something more to the left. Any idea how I can fix this?
Try this
CGRect frame = self.scrollView.bounds;
float offset=20;
frame.size.width = frame.size.width-(2*offset);
frame.origin.x = (320 * page)+offset;
frame.origin.y = 0;
UITableView *tableStage = [[UITableView alloc]initWithFrame:frame];
and no need for this line
tableStage.contentMode = UIViewContentModeScaleAspectFit;
CGRect frame = self.scrollView.bounds;
frame.size.width = 280.0f;
frame.size.height = self.scrollView.bounds.size.height;
frame.origin.x = (self.scrollView.bounds.size.width * page)+(self.scrollView.bounds.size.width - (frame.size.width/2));
frame.origin.y = 0;
If you set the content size properly and the location of each new table view it will work perfectly.Also enable the paging.

Programmatically create UIButtons on CircleImage

I need to create Arch shaped UIButtons, on a circle image.(the O/p need to look like Concentric Circles),
At present I am using 5 images, but in future I may add some more Images, Dynamically I need to fil the circle Image with the added images.
I had a sample Piece of code and O/P is the below image
int numberOfSections = 6;
CGFloat angleSize = 2*M_PI/numberOfSections;
for (int j = 0; j < numberOfSections; ++j) {
UIButton *sectionLabel = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 2.0f)];
sectionLabel.backgroundColor = [UIColor redColor];
sectionLabel.layer.anchorPoint = CGPointMake(1.0f, 0.5f);
sectionLabel.layer.position = CGPointMake(container.bounds.size.width/2.0, container.bounds.size.height/2.0); // places anchorPoint of each label directly in the center of the circle.
sectionLabel.transform = CGAffineTransformMakeRotation(angleSize*j);
[container addSubview:sectionLabel];
}
I have tried with this piece of code and the O/P is the below image
int numberOfSections = 5;
CGFloat angleSize = 2*M_PI/numberOfSections;
for (int j = 0; j<numberOfSections; ++j) {
UIImage *imageframe = [imagesArray objectAtIndex:j];
OBShapedButton *button = [[OBShapedButton alloc] initWithFrame:CGRectMake(0.0f, 150.0f, 150.0f, 128.0f)];
button.transform = CGAffineTransformMakeRotation(angleSize*j);
[container addSubview:button];
}
I need my output as the below image
How can i Achieve that
O/P after I Tried with Sarah Zuo's code
same width and height buttons
AnyKind of Help is more Appreciated
I can answer only last part,
If you are able to get images for buttons, then you can refer this tutorial. This might help you. Provided, your image formed is having transparent background.
float radius = container.bounds.size.width / 2;
int numberOfSections = 5;
CGFloat angleSize = 2*M_PI/numberOfSections;
for (int j = 0; j<numberOfSections; ++j) {
UIImage *imageframe = [imagesArray objectAtIndex:j];
OBShapedButton *button = [[OBShapedButton alloc] initWithFrame:CGRectMake(0.0f, 150.0f, 150.0f, 128.0f)];
button.transform = CGAffineTransformMakeRotation(2*M_PI-angleSize*j);
button.center = CGPointMake(radius + radius * sin(angleSize * j) / 2, radius + radius * cos(angleSize * j) / 2);
[container addSubview:button];
}
Try this code.
You can use your UIImageView instead. You can give different tag to image view and add Gesture Recognizer. Now you can get touch events like button click event on image views.
If all buttons' image look like the one (same direction), the transform value may be work.
button.transform = CGAffineTransformMakeRotation(2*M_PI-angleSize*j);
button.center = CGPointMake(radius + radius * sin(angleSize * j) / 2, radius + radius * cos(angleSize * j) / 2);

Move left and right in UIScrollView

I have a UIScrollView which scrolls only horizontally. I have a situation where I have views filled by array in UIScrollView. There are three views which altogether make one single component in UIScrollView (there are many such components). Component contains :
UILabel
UIButton
UIView (for underlying text)
I have placed two arrow keys(left and right) at the ends of UIScrollView. On touching left arrow I am shifting one position left (with complete string to display) in UIScrollView and one position right (with complete string to display) in case of right arrow button.
Till now I am able to perform left arrow action. But I have no idea how to perform right arrow touch and how to display complete string to touching arrow keys if only part of that string is being displayed.
I know it is weird that I have a UIScrollView and still want to add arrow keys to move it. But can't help it. This is client's requirement. The following is how I implemented left arrow action:
-(IBAction) onClickLeftArrow
{
NSLog(#"BUTTON VALUE : %i",iButtonValue);
if(iButtonValue <= [m_BCListArray count]) {
NSArray *arr = [scrollDemo subviews];
for(int j = 0; j < [arr count]; j++) {
UIView *view1 = [arr objectAtIndex:j];
[view1 removeFromSuperview];
}
XX = 5.0;
int tagcount = [m_BCListArray count]-iButtonValue;
NSLog(#"%#",m_BCListArray);
for(int i = iButtonValue; i >= 1; i--)
{
UILabel *blabel = [[UILabel alloc] initWithFrame:CGRectMake(XX, 6, 120, 26)];
blabel.text = [m_BCListArray objectAtIndex:[m_BCListArray count]-i];
blabel.backgroundColor = [UIColor clearColor];
blabel.textColor = [UIColor whiteColor];
blabel.font = [UIFont systemFontOfSize:14];
[scrollDemo addSubview:blabel];
//underline code
CGSize expectedLabelSize = [[m_BCListArray objectAtIndex:[m_BCListArray count]-1] sizeWithFont:blabel.font constrainedToSize:blabel.frame.size lineBreakMode:UILineBreakModeWordWrap];
CGRect newFrame = blabel.frame;
newFrame.size.height = expectedLabelSize.height;
blabel.frame = CGRectMake(blabel.frame.origin.x, blabel.frame.origin.y, expectedLabelSize.width+10, expectedLabelSize.height);
blabel.numberOfLines = 1;
[blabel sizeToFit];
int width=blabel.bounds.size.width;
int height=blabel.bounds.size.height;
UIButton *btnContent = [UIButton buttonWithType:UIButtonTypeCustom];
[btnContent addTarget:self action:#selector(SelectButton:)forControlEvents:UIControlEventTouchDown];
btnContent.tag = tagcount+1;
btnContent.frame=CGRectMake(XX, 2.0, width+10, height);
[scrollDemo addSubview:btnContent];
scrollDemo.contentSize = CGSizeMake(XX+50, 32);
//scrollDemo.contentSize = CGSizeMake(expectedLabelSize.width,expectedLabelSize.height);
UIView *viewUnderline=[[UIView alloc] init];
viewUnderline.frame=CGRectMake(XX, 26, width, 1);
viewUnderline.backgroundColor=[UIColor whiteColor];
[scrollDemo addSubview:viewUnderline];
[viewUnderline release];
scrollDemo.contentSize = CGSizeMake(XX+width+10, 32);
XX = XX + width+10;
iRight = iRight + 1;
tagcount ++;
// iRight --;
}
}
iButtonValue = iButtonValue+1;
}
Set the contentOffset of UIScrollView on the Button click action and u'll get your desired effect.

UIScrollView paging load from nib just 1 NIB show

i'm new on object-C, i want show some NIB file to UIScrollView with paging, i'm do it but just 1 NIB showing, other nib not show, the sample i make 2 page on each page have NIB, this is code :
bbottompageused = NO;
CGRect frame;
int tview=2;
mycontact = [[MyContact alloc] initWithNibName:#"MyContact" bundle:nil];
myphoto = [[MyPhoto alloc] initWithNibName:#"MyPhoto" bundle:nil];
frame.origin.x = self.midleScroll.frame.size.width * 1;
frame.origin.y = 0;
frame.size = self.midleScroll.frame.size;
[self.midleScroll addSubview:mycontact.view];
frame.origin.x = self.midleScroll.frame.size.width * 2;
frame.origin.y = 0;
frame.size = self.midleScroll.frame.size;
[self.midleScroll addSubview:myphoto.view];
self.midleScroll.contentSize = CGSizeMake(self.midleScroll.frame.size.width * tview, self.midleScroll.frame.size.height);
self.midlePage.currentPage = 0;
self.midlePage.numberOfPages = tview;
Have anyone suggestion for solve this ?
Thanks all,
assign the frame that you have to your views (myContact, myPhoto) and then add them to the scroll view.
You configure the frame but you don't assign this frame to myContact.view and myPhoto.view.
Hence, both of the myContact.view.frame and myPhoto.view.frame remain unchanged.
Do the following:
bbottompageused = NO;
CGRect frame;
int tview=2;
mycontact = [[MyContact alloc] initWithNibName:#"MyContact" bundle:nil];
myphoto = [[MyPhoto alloc] initWithNibName:#"MyPhoto" bundle:nil];
frame.origin.x = self.midleScroll.frame.size.width * 1;
frame.origin.y = 0;
frame.size = self.midleScroll.frame.size;
// Assign the frame
myContact.view.frame = frame;
[self.midleScroll addSubview:mycontact.view];
frame.origin.x = self.midleScroll.frame.size.width * 2;
frame.origin.y = 0;
frame.size = self.midleScroll.frame.size;
// Assign the frame
myPhoto.view.frame = frame;
[self.midleScroll addSubview:myphoto.view];
self.midleScroll.contentSize = CGSizeMake(self.midleScroll.frame.size.width * tview, self.midleScroll.frame.size.height);
self.midlePage.currentPage = 0;
self.midlePage.numberOfPages = tview;

offset a image view from another imageview?

I'm trying to set an imageviews origin to offset from another imaeviews origin but am having no luck a all.. I wanna be able to offset the other imageview so it doesn't appear directly ontop of it but a little to the left or right of the images center and up a little bit.
here's my code.
imageView1.center = CGPointMake(imageView2.center.x + 20, imageView2.center.y + 35);
probably easier to deal with origins...
kOffset = 5;
kWidth = 50
kHeight = 50;
CGRect frame = CGRectMake(0,0, kWidth, kHeight);
UIImageView *theImage;
for(int i = 0; i<numberOfImages; i++){
theImage = [[UIImageView alloc] initWithFrame:frame];
frame.origin.x += (kWidth + kOffset);
}