i am writing this code to load a plist into 2 textview but i want them to adjust their height according to content size which i have done but i want the second uitextview to start from where the first one ends .. please help
for (int i = 0; i < arrresult.count; i++) {
NSArray *sorteddetail = [self.arrresult sortedArrayUsingFunction:sortint context:NULL];
DuaObject *duaobj2 = [[DuaObject alloc] initWithFilePath:[sorteddetail objectAtIndex:i]];
[duaobj2 loadFile];
CGRect frame;
frame.origin.x = self.scrollmain.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollmain.frame.size;
UITextView *subview = [[UITextView alloc] initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+10, 230, 120)];
UITextView *subview2 = [[UITextView alloc]initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+160,230, 120)];
subview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"BG_text.png"]];
subview2.backgroundColor = [UIColor whiteColor];
[subview setFont:[UIFont boldSystemFontOfSize:14]];
[subview2 setFont:[UIFont boldSystemFontOfSize:14]];
subview.layer.cornerRadius = 10 ;
subview2.layer.cornerRadius = 10;
NSString *p = [duaobj2 dua_arabic];
NSString *b = [duaobj2 eng_trans];
subview.text = p;
subview2.text = b;
[self.scrollmain addSubview:subview];
[self.scrollmain addSubview:subview2];
subview.editable = NO;
subview2.editable = NO;
subview.textColor = [UIColor blackColor];
subview2.textColor = [UIColor blackColor];
subview.backgroundColor = [UIColor whiteColor];
subview2.backgroundColor = [UIColor whiteColor];
scrollmain.showsHorizontalScrollIndicator = NO;
CGRect frame1 = subview.frame;
CGRect frame2 = subview2.frame;
frame1.size.height = subview.contentSize.height;
frame2.size.height = subview2.contentSize.height;
subview.frame = frame1;
subview2.frame = frame2;
}
You can use two UIWebView for this. After fetching text data from plist ,redirect it on particular web view. and use [webView stringByEvaluatingJavaScriptFromString:#"document.body.offsetHeight;"] method to get height in pixel. According to height of pixel you can re-adjust web views frame.
Edit:
Look this one : How do I size a UITextView to its content?
It will help you.
Related
My app's UIScrollView Sliding automatic will bounce back,what can i do?
I do not want!
my code below:
- (void)initScrollView {
// a page is the width of the scroll view
sv = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 96, 320, 300)];
sv.contentSize = CGSizeMake(sv.frame.size.width * 3, sv.frame.size.height* 2);
sv.pagingEnabled = YES;
sv.clipsToBounds = YES;
sv.showsHorizontalScrollIndicator = NO;
sv.showsVerticalScrollIndicator = YES;
sv.scrollsToTop = NO;
sv.directionalLockEnabled = YES;
sv.delegate = self;
[self.view addSubview:sv];
currentPage = 0;
pageControl.numberOfPages = 3;
pageControl.currentPage = 0;
pageControl.backgroundColor = [UIColor clearColor];
[self createAllEmptyPagesForScrollView];
}
- (void)createAllEmptyPagesForScrollView {
tapView1 = [[UIView alloc]init];
tapView1.backgroundColor = [UIColor clearColor];
tapView1.frame = CGRectMake(320*0, 0, 320, sv.frame.size.height);
tapView2 = [[UIView alloc]init];
tapView2.backgroundColor = [UIColor clearColor];
tapView2.frame = CGRectMake(320*1, 0, 320, sv.frame.size.height);
tapView3 = [[UIView alloc]init];
tapView3.backgroundColor = [UIColor clearColor];
tapView3.frame = CGRectMake(320*2, 0, 320, sv.frame.size.height);
[sv addSubview:tapView1];
[sv addSubview:tapView2];
[sv addSubview:tapView3];
}
i konw why I slide up automatically bounce back,my code have problem!Not bove code!thanks everyone!
- (void)viewDidLoad
{
MyData *data = [MyData SharedData];
scrollerView.pagingEnabled = YES;
scrollerView.bounces = YES;
int numberOfViews = [data.placePhotos count];
for (int i = 0; i < numberOfViews; i++) {
CGFloat yOrigin = i * self.view.frame.size.width;
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
awesomeView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 300 , 320)];
NSString * photourl = [[data.placePhotos objectAtIndex:i] stringByReplacingOccurrencesOfString:#"150x75" withString:#"440x440"];
[imageView setImageWithURL:[NSURL URLWithString:photourl]];
[awesomeView addSubview:imageView];
[scrollerView addSubview:awesomeView];
awesomeView = nil;
imageView =nil;
}
I added the UIScrollView in the .xib file , when i tried to pull the scroll view from left to right it does not move, i have 4 subviews added but why i can not view them ?
you should set the content size the scrollView
[self. scrollerView setContentSize:CGSizeMake(320, 1000)];
Give your width and heigth.
add scrollerView.contentSize = CGSizeMake(yOrigin + self.view.frame.size.width, scrollerView.frame.size.height); after the loop (even though I'm a little bit confused about why the x-origin is called yOrigin in your code...)
How to remove subviews from superviews and redraw on a click a button click?
float padding = 5.0;
float view_width = 95.0;
float view_height = 120.0;
int rows = 0.0f;
int columns = 0.0f;
UIView *myAddedView ;
for (int i=0; i<[product.CorrentAnswer intValue]; i++)
{
if(i%3 == 0 && i > 0)
{
columns = 0.0f;
rows += view_height;
}
myAddedView =[[[UIView alloc] initWithFrame:CGRectMake(padding+columns, rows, view_width, view_height)] autorelease];
myAddedView.backgroundColor = [UIColor clearColor];
CGRect myImageRect = CGRectMake( 40, 100.0f, 40.0f, 40.0f);
UIImageView *myImage = [[UIImageView alloc]initWithFrame:myImageRect];
NSString *imageName = [NSString stringWithFormat:#"%#",product.imagename];
[myImage setImage:[UIImage imageNamed:imageName]];
[myAddedView addSubview:myImage];
[viewarray addObject:myAddedView];
[self.view addSubview:myAddedView];
columns+= view_width;
}
i want to remove myAddedView from self.view?
hope to get answer very soon....
you can do this by assigning a tag to myAddedView ....
code change :
myAddedView =[[[UIView alloc] initWithFrame:CGRectMake(padding+columns, rows, view_width, view_height)] autorelease];
myAddedView.backgroundColor = [UIColor clearColor];
//add this line
myAddedView.tag = 10;
and on the button click(when you want to remove the subview) write :
if([self.view viewWithTag:10]!=nil)
{
[[self.view viewWithTag:10] removeFromSuperView];
}
thanks
the answer from user698952 is okay, adding a tag is the way to go.
myAddedView.tag = 10;
If you have more than one view with the same tag you have to change the code for removal a little bit.
UIView *someView = nil;
while (someView = [self.view viewWithTag:10]) {
[someView removeFromSuperview];
}
HI,
I am using the following code for displaying data dynamically on a label.ITs working fine.But sometimes the content is overlapping with the subhead title and description.Please help me in this.I am not able to trace out this.THANKS IN ADVANCE
for (int i=0; i<[article.subheadArray count]; i++) {
//subhead Title
subheadTitle = [[UILabel alloc] initWithFrame:CGRectMake(xoffset, yoffset+total, 320-xoffset, 300+lblheight)];
subheadTitle.backgroundColor=[UIColor clearColor];
//subheadTitle.textColor=[UIColor blueColor];
[subheadTitle setFont: [UIFont fontWithName:#"Arial-BoldMT" size:17]];
subheadTitle.textColor = [UIColor colorWithRed:45.0/255.0 green:99.0/255.0 blue:03.0/255.0 alpha:1];
subHead = [article.subheadArray objectAtIndex:i];
expectedLabelSize = [subHead.Title sizeWithFont:subheadTitle.font
constrainedToSize:maximumLabelSize
lineBreakMode:subheadTitle.lineBreakMode];
newFrame = subheadTitle.frame;
newFrame.size.height=expectedLabelSize.height;
subheadTitle.frame=newFrame;
total+=expectedLabelSize.height+yoffset;
NSLog(#"%# %d",subHead.Title,total);
subheadTitle.numberOfLines=0;
subheadTitle.text=subHead.Title;
[scrollView addSubview:subheadTitle];
//subhead Description
subheadlabel = [[UILabel alloc] initWithFrame:CGRectMake(xoffset, yoffset+total, 320-xoffset, 300+lblheight)];
subheadlabel.backgroundColor=[UIColor clearColor];
subHead = [article.subheadArray objectAtIndex:i];
//subheadlabel.font = [UIFont italicSystemFontOfSize:fontsize];
[subheadlabel setFont: [UIFont fontWithName:#"ArialMT" size:fontsize]];
expectedLabelSize=[subHead.Description sizeWithFont:subheadlabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:subheadlabel.lineBreakMode];
newFrame = subheadlabel.frame;
newFrame.size.height=expectedLabelSize.height;
subheadlabel.frame=newFrame;
total+=expectedLabelSize.height+yoffset;
subheadlabel.text = subHead.Description;
NSLog(#"subhead desc: %d %d",total,subheadlabel.numberOfLines);
subheadlabel.numberOfLines =0;
[subheadlabel sizeToFit];
[scrollView addSubview:subheadlabel];
//Adding subhead label to subheadlabelarr
[subheadlabelarr addObject:subheadTitle];
//subhead Image
for (int j=0; j<[subHead.imageArray count]; j++) {
Image* image = [subHead.imageArray objectAtIndex:j];
UIImage* uiImage = [XMLParsing getImagewithName:image.Name];
CGSize imageSize = uiImage.size;
if(imageSize.width>=300){
width = 300;
}
else {
width = imageSize.width;
}
if(imageSize.height>=200){
height = 200;
}else {
height = imageSize.height;
}
imageView = [[UIImageView alloc] initWithFrame:CGRectMake((320-width)/2,yoffset+total,width,height)];
//imageView = [[UIImageView alloc] initWithFrame:CGRectMake(200, yoffset+total, width, height)];
imageView.clipsToBounds = YES;
total+=imageView.frame.size.height+yoffset;
//************cell.myImageView.image=[XMLParser getImagewithName:#"og_logo.png"];
imageView.image = [XMLParsing getImagewithName:image.Name];
[scrollView addSubview:imageView];
}
}
I think both subheadTitle and subheadlabel will overlaps because of their frame. Can you check the values of expectedLabelSize in both cases.
Is there a way to rotate an UIPickerView?
//example code placed in view did Load
[super viewDidLoad];
myPicker.delegate = self;
myPicker.dataSource = self;
myPicker.showsSelectionIndicator =YES;
myPicker.backgroundColor = [UIColor blackColor];
CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2);
//original settings
//rotate = CGAffineTransformScale(rotate, 0.1, 0.8);
rotate = CGAffineTransformScale(rotate, 0.2, 1.65);
[self.myPicker setTransform:rotate];
NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:#"155", #"165", #"175",
#"185", #"195", #"205", #"215", nil];
self.pickerData = array;
[array release];
NSInteger TOTALITEM = [pickerData count];
UILabel *theview[TOTALITEM-1]; // + 1 for the nil
for (int i=1;i<=TOTALITEM-1;i++) {
theview[i] = [[UILabel alloc] init];
theview[i].text = [NSString stringWithFormat:#"%d",i];
theview[i].textColor = [UIColor blackColor];
theview[i].frame = CGRectMake(0,0, 25, 25);
theview[i].backgroundColor = [UIColor clearColor];
theview[i].textAlignment = UITextAlignmentCenter;
theview[i].shadowColor = [UIColor whiteColor];
theview[i].shadowOffset = CGSizeMake(-1,-1);
theview[i].adjustsFontSizeToFitWidth = NO;
UIFont *myFont = [UIFont fontWithName:#"Helvetica" size:30];
[theview[i] setFont:myFont];
}
CGAffineTransform rotateItem = CGAffineTransformMakeRotation(-3.14/2);
rotateItem = CGAffineTransformScale(rotateItem, .5, 5);
for (int j=1;j<=TOTALITEM-1;j++) {
theview[j].transform = rotateItem;
}
pickerData = [[NSMutableArray alloc] init];
for (int j=1;j<=TOTALITEM-1;j++) {
[pickerData addObject:theview[j]];
}
You can rotate a UIPickerView by applying a transform to a view containing it, much like I suggest in my answer here for scaling the picker.
Are you looking for - (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated?
Or do you mean that you want to rotate the whole control 90 degrees, thus having wheels that spin to the left and right?