hello I am using HMSegmentedControl for swipe tab feature. And my code is like this.
// Tying up the segmented control to a scroll view
self.segmentedControl4 = [[HMSegmentedControl alloc] initWithFrame:CGRectMake(0, 260, viewWidth, 50)];
self.segmentedControl4.sectionTitles = #[#"Worldwide", #"Local", #"Headlines",#"Four",#"Five"];
self.segmentedControl4.selectedSegmentIndex = 1;
self.segmentedControl4.backgroundColor = [UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:1];
self.segmentedControl4.titleTextAttributes = #{NSForegroundColorAttributeName : [UIColor whiteColor]};
self.segmentedControl4.selectedTitleTextAttributes = #{NSForegroundColorAttributeName : [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1]};
self.segmentedControl4.selectionIndicatorColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1];
self.segmentedControl4.selectionStyle = HMSegmentedControlSelectionStyleBox;
self.segmentedControl4.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationUp;
self.segmentedControl4.tag = 3;
__weak typeof(self) weakSelf = self;
[self.segmentedControl4 setIndexChangeBlock:^(NSInteger index) {
[weakSelf.scrollView scrollRectToVisible:CGRectMake(viewWidth * index, 0, viewWidth, 200) animated:YES];
}];
[self.view addSubview:self.segmentedControl4];
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 310, viewWidth, 210)];
self.scrollView.backgroundColor = [UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:1];
self.scrollView.pagingEnabled = YES;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.contentSize = CGSizeMake(viewWidth * 5, 200);
self.scrollView.delegate = self;
[self.scrollView scrollRectToVisible:CGRectMake(viewWidth, 0, viewWidth, 200) animated:NO];
[self.view addSubview:self.scrollView];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, viewWidth, 210)];
[self setApperanceForLabel:label1];
label1.text = #"Worldwide";
[self.scrollView addSubview:label1];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(viewWidth, 0, viewWidth, 210)];
[self setApperanceForLabel:label2];
label2.text = #"Local";
[self.scrollView addSubview:label2];
UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(viewWidth * 2, 0, viewWidth, 210)];
[self setApperanceForLabel:label3];
label3.text = #"Headlines";
[self.scrollView addSubview:label3];
UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(viewWidth * 2, 0, viewWidth, 210)];
[self setApperanceForLabel:label4];
label4.text = #"Four";
[self.scrollView addSubview:label4];
UILabel *label5 = [[UILabel alloc] initWithFrame:CGRectMake(viewWidth * 2, 0, viewWidth, 210)];
[self setApperanceForLabel:label5];
label5.text = #"Five";
[self.scrollView addSubview:label5];
My problem is it doesnt show these label4 and label 5 only show upto 3. But all 5 titles show from the section titles array. How can I solve these problem.
Please help me.
ThanksThis is the github project I used
I don't know about HMSegmentedControl but i use Page Menu for scroll pages like segment controller. you can add your view controller directly into this menu segment.
I am not sure that this is a perfect answer of this question but it might help others as well.
Set your self.segmentedControl4.tag = 5;
Give tag numbers which you want to show in segmentedControl.
Related
I want to scroll up and down in my page without using AutoLayout in Xcode. How do I make the scrolling work?
I want to show the second question label and text and add other labels and fields. But I can't scroll to see how they look after building the project
This is the viewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImage *bg = [UIImage imageNamed:#"logo2.jpg"];
self.myImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
self.myImageView.image = bg;
self.myImageView.contentMode = UIViewContentModeScaleAspectFit;
self.myImageView.center = self.view.center;
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.myImageView];
CGRect scrollViewRect = self.view.bounds;
self.myScrollView = [[UIScrollView alloc] initWithFrame:scrollViewRect];
self.myScrollView.pagingEnabled = YES;
self.myScrollView.scrollEnabled = YES;
self.myScrollView.contentSize = CGSizeMake(self.myScrollView.frame.size.width + 100, self.myScrollView.frame.size.height + 100);
[self.view addSubview:self.myScrollView];
float width = CGRectGetWidth(self.myScrollView.frame);
float height = CGRectGetHeight(self.myScrollView.frame);
float newPosition = self.myScrollView.contentOffset.y+height;
CGRect toVisible = CGRectMake(newPosition, 0, width, height);
[self.myScrollView scrollRectToVisible:toVisible animated:YES];
//FirstNameLabel
CGRect labelFirst = CGRectMake(10, 100, 100, 30);
self.firstnamelabel = [[UILabel alloc] initWithFrame:labelFirst];
self.firstnamelabel.font = [UIFont boldSystemFontOfSize:15.0f];
self.firstnamelabel.text = #"First Name : ";
//FirstNameField
CGRect firsttextField = CGRectMake(100, 100, 200, 30);
self.firstnametext = [[UITextField alloc] initWithFrame:firsttextField];
self.firstnametext.borderStyle = UITextBorderStyleRoundedRect;
//LastNameLabel
CGRect labelLast = CGRectMake(10, 150, 100, 30);
self.lastnamelabel = [[UILabel alloc] initWithFrame:labelLast];
self.lastnamelabel.font = [UIFont boldSystemFontOfSize:15.0f];
self.lastnamelabel.text = #"Last Name : ";
//LastNameTextField
CGRect lasttextField = CGRectMake(100, 150, 200, 30);
self.lastnametext = [[UITextField alloc] initWithFrame:lasttextField];
self.lastnametext.borderStyle = UITextBorderStyleRoundedRect;
//DateLabel
CGRect labeldate = CGRectMake(10, 190, 100, 30);
self.DateOfBirthLabel = [[UILabel alloc] initWithFrame:labeldate];
self.DateOfBirthLabel.font = [UIFont boldSystemFontOfSize:15.0f];
self.DateOfBirthLabel.text = #"Date Of Birth: ";
//DatePicker
CGRect datepickersize=CGRectMake(10, 210, 300, 150);
self.datepicker=[[UIDatePicker alloc] initWithFrame:datepickersize];
NSDate *date= self.datepicker.date;
self.datepicker.datePickerMode=UIDatePickerModeDate;
//Email
CGRect labelemail = CGRectMake(30, 370, 100, 30);
self.emaillabel = [[UILabel alloc] initWithFrame:labelemail];
self.emaillabel.font = [UIFont boldSystemFontOfSize:15.0f];
self.emaillabel.text = #"Email : ";
//EmailText
CGRect emailtextField = CGRectMake(100, 370, 200, 30);
self.emailtext = [[UITextField alloc] initWithFrame:emailtextField];
self.emailtext.borderStyle = UITextBorderStyleRoundedRect;
//PasswordLabel
CGRect labelpassword = CGRectMake(10, 410, 100, 30);
self.passwordlabel = [[UILabel alloc] initWithFrame:labelpassword];
self.passwordlabel.font = [UIFont boldSystemFontOfSize:15.0f];
self.passwordlabel.text = #"Password : ";
//PasswordText
CGRect passwordtextField = CGRectMake(100, 410, 180, 30);
self.passwordtext = [[UITextField alloc] initWithFrame:passwordtextField];
self.passwordtext.borderStyle = UITextBorderStyleRoundedRect;
self.passwordtext.secureTextEntry = true;
//eyebutton
UIImage *eye = [UIImage imageNamed:#"eye.png"];
self.eyebutton = [UIButton buttonWithType:UIButtonTypeCustom];
self.eyebutton.frame = CGRectMake(290, 415, 20, 20);
[self.eyebutton setImage:eye forState:UIControlStateNormal];
[self.eyebutton addTarget:self action:#selector(touchDown) forControlEvents:UIControlEventTouchDown];
[self.eyebutton addTarget:self action:#selector(touchUpInside) forControlEvents:UIControlEventTouchUpInside];
//FirstQuetionLabel
CGRect labelfq = CGRectMake(10, 450, 300, 20);
self.firstQuestlabel = [[UILabel alloc] initWithFrame:labelfq];
self.firstQuestlabel.font = [UIFont boldSystemFontOfSize:14.0f];
self.firstQuestlabel.text = #"Question 1: In which city you were born in?";
//FirstQuestionTextField
CGRect fqtextField = CGRectMake(10, 470, 240, 30);
self.firstQuestionText = [[UITextField alloc] initWithFrame:fqtextField];
self.firstQuestionText.borderStyle = UITextBorderStyleRoundedRect;
//SecondQuestionLabel
CGRect labelsq = CGRectMake(10, 500, 300, 30);
self.secondQuestLabel = [[UILabel alloc] initWithFrame:labelsq];
self.secondQuestLabel.font = [UIFont boldSystemFontOfSize:13.0f];
self.secondQuestLabel.text = #"Question 2: What is your mother's \rmiddle name?";
//SecondQuestionTextField
CGRect sqtextField = CGRectMake(10, 630, 240, 30);
self.secondQuestionText = [[UITextField alloc] initWithFrame:sqtextField];
self.secondQuestionText.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:self.eyebutton];
[self.view addSubview:self.firstnamelabel];
[self.view addSubview:self.firstnametext];
[self.view addSubview:self.lastnamelabel];
[self.view addSubview:self.lastnametext];
[self.view addSubview:self.DateOfBirthLabel];
[self.view addSubview:self.datepicker];
[self.view addSubview:self.emaillabel];
[self.view addSubview:self.emailtext];
[self.view addSubview:self.passwordlabel];
[self.view addSubview:self.passwordtext];
[self.view addSubview:self.firstQuestlabel];
[self.view addSubview:self.firstQuestionText];
[self.view addSubview:self.secondQuestLabel];
[self.view addSubview:self.secondQuestionText];
}
At first glance, scrolling may not be enabled because you have not set the contentSize property of the scroll view. To set allow scrolling, the contentSize needs to be set to be larger than the frame of the scroll view.
An example in objective-c would be:
self.myScrollView.contentSize = CGSizeMake(self.myScrollView.frame.size.width + 20, self.myScrollView.frame.size.height + 20);
Updated for edited question
Any views you want to be scrollable within your scroll view need to be added as a subview on the scrollView i.e
[self.myScrollView addSubview: myLabel]; //do for all views that you want to be scrollable in the scrollView
Then you need find the sum height of all the views contained in your scroll view i.e
CGFloat sumHeight = myLabel1.frame.size.height + myView2.frame.size.height; //etc do for all views you want in your scrollView
then set it to be your contentSize ie
self.myScrollView.contentSize = CGSizeMake(self.myScrollView.frame.size.width, sumHeight);
I have an app.In this app so many class methods used.I want to know is it possible to remove subview from class mehtod?
+(void)addPregressIndicator:(NSString *)strText view:(UIView *)ShowView
{
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
UIView *busyView = [[UIView alloc] initWithFrame:appFrame];
busyView.backgroundColor = [UIColor clearColor];
busyView.opaque = YES;
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 95, 95)];
container.layer.borderWidth = 5;
container.layer.cornerRadius = 10;
container.layer.borderColor = [UIColor whiteColor].CGColor;
[container setBackgroundColor:[UIColor blackColor]];
UIActivityIndicatorView *av = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
av.center = CGPointMake(container.center.x, 34);
av.hidesWhenStopped = NO;
[av startAnimating];
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 95, 30)];
lbl.text = strText;
lbl.textAlignment = NSTextAlignmentCenter;
lbl.center = CGPointMake(container.center.x, 70);
lbl.textColor = [UIColor whiteColor];
lbl.backgroundColor = [UIColor clearColor];
[container addSubview:av];
[container addSubview:lbl];
container.center = busyView.center;
[busyView addSubview:container];
[ShowView addSubview:busyView];
}
+(void)removePregressIndicator:(UIView *)hideView;
{
// i want remove busyview that subview in viewcontroller.
}
Please help me to remove subivew.
You can set a unique tag for the busyView like this busyView.tag = your unique tag;
And then you can remove the view with this code
+(void)removePregressIndicator:(UIView *)hideView;
{
UIView *busyView = [hideView viewWithTag:your unique tag];
if (busyView){
[busyView removeFromSuperview];
}
}
You should make sure that the busyView tag is unique for all the subviews of hideView.
Assigne tag to a each view and access the view with tag and put it
+(void)removePregressIndicator:(UIView *)hideView;
{
UIView *viewToRemove = [self.view viewWithTag:assigne_tag];
[viewToRemove removeFromSuperview];
}
+ (void)removePregressIndicator:(UIView *)hideView;
{
UIView *progView=[self.view viewWithTag:YourTag];
[progView removeFromSuperview];
}
Hi i am beginner in iOS and in my project i need to insert "titles" at "left side center" and "right side center" on UInavigationBar as like below image please help me how should i do below my requirement
See below code and try :
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = [[UIScreen mainScreen] bounds];
UILabel *lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width/2, 44)];
lbl1.backgroundColor = [UIColor redColor];
lbl1.textAlignment = NSTextAlignmentCenter;
lbl1.text = #"Dashboard";
[self.navigationController.navigationBar addSubview:lbl1];
UILabel *lbl2 = [[UILabel alloc] initWithFrame:CGRectMake(frame.size.width/2, 0, frame.size.width/2, 44)];
lbl2.backgroundColor = [UIColor redColor];
lbl2.textAlignment = NSTextAlignmentCenter;
lbl2.text = #"Profile";
[self.navigationController.navigationBar addSubview:lbl2];
}
You can customize the titleView of navigation bar. Read the official documentation here.
As per your question, I tried the below working code:-
-(UIView *)getTitleView
{
CGRect frame = [[UIScreen mainScreen] bounds];
UIView *viewTitle = [[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, self.navigationController.navigationBar.frame.size.height)];
UILabel *lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width/2, self.navigationController.navigationBar.frame.size.height)];
lbl1.backgroundColor = [UIColor colorWithRed:130/255.0f green:13/255.0f blue:23/255.0f alpha:1.0f];
lbl1.textAlignment = NSTextAlignmentCenter;
[lbl1 setTextColor:[UIColor whiteColor]];
lbl1.text = #"Dashboard";
[viewTitle addSubview:lbl1];
UILabel *lbl2 = [[UILabel alloc] initWithFrame:CGRectMake(frame.size.width/2, 0, frame.size.width/2, viewTitle.frame.size.height)];
lbl2.backgroundColor = [UIColor colorWithRed:130/255.0f green:13/255.0f blue:23/255.0f alpha:1.0f];
[lbl2 setTextColor:[UIColor whiteColor]];
lbl2.textAlignment = NSTextAlignmentCenter;
lbl2.text = #"Profile";
[viewTitle addSubview:lbl2];
return viewTitle;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.titleView = [self getTitleView];
}
I divide the code in separate method to follow modular approach. For any part of code, which is of separate task, write that piece of code in different method. This will lead to more readability.
I am trying to add the uiLabel on top of the uiImageVIew which is the background image. When it comes to adding the uiLabel on top of the uiImageView, the uilabel cannot be aded when testing and running. Would you please tell me the alternatives or precautions if doing so ?
The below is my code :
#implementation CoverViewController
- (void)viewDidLoad {
[super viewDidLoad];
_container = [[UIView alloc] initWithFrame:[self.view bounds]];
[self setTapDemo :[UIImage imageNamed:#"cover_1_d.png"] ] ;
}
- (void) setTapDemo: (UIImage *) cover {
_image = [UIImage imageNamed:#"shaded_region.png"];
_imageShaded = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[_imageShaded setImage:_image];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[imageView setImage: cover ];
_imageShaded.userInteractionEnabled = YES;
UITapGestureRecognizer *myGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(touchesBegan:)];
myGesture.numberOfTapsRequired = 1;
myGesture.delegate=self;
[_imageShaded addGestureRecognizer:myGesture];
[_imageShaded setContentMode:UIViewContentModeScaleAspectFill];
NSString * text = #"Quad name:";
CGSize labelSize = CGSizeMake(60, CGFLOAT_MAX);
UILabel *fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(91, 15, labelSize.width, labelSize.height)];
fromLabel.text = text;
fromLabel.numberOfLines = 1;
fromLabel.lineBreakMode = NSLineBreakByWordWrapping;
fromLabel.baselineAdjustment = UIBaselineAdjustmentAlignBaselines; // or UIBaselineAdjustmentAlignCenters, or UIBaselineAdjustmentNone
fromLabel.adjustsFontSizeToFitWidth = YES;
fromLabel.minimumScaleFactor = 10.0f/12.0f;
fromLabel.clipsToBounds = YES;
fromLabel.backgroundColor = [UIColor clearColor];
fromLabel.textAlignment = NSTextAlignmentLeft;
[_imageShaded addSubview:fromLabel];
[imageView addSubview:fromLabel];
[_container addSubview:_imageShaded];
[_container addSubview:imageView];
[_container addSubview:fromLabel];
[self.view addSubview:_container];
[self.view sendSubviewToBack:_container];
}
Check This
- (void) setTapDemo: (UIImage *) cover {
_image = [UIImage imageNamed:#"images.jpg"];
_imageShaded = [[UIImageView alloc] initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height)];
[_imageShaded setImage:_image];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height)];
[imageView setImage: cover ];
_imageShaded.userInteractionEnabled = YES;
UITapGestureRecognizer *myGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(touchesBegan:)];
myGesture.numberOfTapsRequired = 1;
myGesture.delegate=self;
[_imageShaded addGestureRecognizer:myGesture];
[_imageShaded setContentMode:UIViewContentModeScaleAspectFill];
NSString * text = #"Quad name:";
// CGSize labelSize = CGSizeMake(60, CGFLOAT_MAX);
UILabel *fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(91, 15, 300, 40)];
fromLabel.text = text;
fromLabel.textColor = [UIColor greenColor];
fromLabel.numberOfLines = 1;
fromLabel.lineBreakMode = NSLineBreakByWordWrapping;
fromLabel.baselineAdjustment = UIBaselineAdjustmentAlignBaselines; // or UIBaselineAdjustmentAlignCenters, or UIBaselineAdjustmentNone
fromLabel.adjustsFontSizeToFitWidth = YES;
fromLabel.minimumScaleFactor = 10.0f/12.0f;
fromLabel.clipsToBounds = YES;
fromLabel.backgroundColor = [UIColor clearColor];
fromLabel.textAlignment = NSTextAlignmentLeft;
[_container addSubview:_imageShaded];
[_container addSubview:imageView];
[self.view addSubview:_container];
[self.view sendSubviewToBack:_container];
[imageView addSubview:fromLabel];
}
You are adding your UILabel more than once on different views. you should add it on a single view at a time;
//[_imageShaded addSubview:fromLabel]; // 1
//[imageView addSubview:fromLabel]; // 2
[_container addSubview:_imageShaded];
[_container addSubview:imageView];
//[_container addSubview:fromLabel]; //3
I have been searching for quite a while now, and every answer I find doesn't seem to work. I have a view, code below, that holds a bunch of text that is pulled from a YouTube video description from another view. Obviously ever video's descriptions are of different length, which is what poses the problem. I want to make it that the scrollview only scrolls down to about 10 pixels after the last text line of the label.
In this code, I don't have it doing that, I have it at a fixed size.
Can ANYONE help? I have been searching for days now, and I can seem to find a proper solution.
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
VideoDescription = [VideoDescription stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//int a = VideoDescription.length;
//NSLog([NSString stringWithFormat:#"%i", a]);
if(VideoDescription.length < 310)
{
VideoDescription = [VideoDescription stringByAppendingString:#"\n_______________________________________________"];
VideoDescription = [VideoDescription stringByAppendingString:#"\n\nFor the best viewing experience, please use WiFi."];
VideoDescription = [VideoDescription stringByAppendingString:#"\n\nWant an app like this for your YouTube Channel? Go to www.apps4tubers.com to find out how you can get one!"];
VideoDescription = [VideoDescription stringByAppendingString:#"\n\nDon't forget to rate this app! Love it? Hate it? Regardless we love to hear your comments and suggestions!"];
}
else if(VideoDescription.length < 380)
{
VideoDescription = [VideoDescription stringByAppendingString:#"\n_______________________________________________"];
VideoDescription = [VideoDescription stringByAppendingString:#"\n\nFor the best viewing experience, please use WiFi."];
VideoDescription = [VideoDescription stringByAppendingString:#"\n\nWant an app like this for your YouTube Channel? Go to www.apps4tubers.com to find out how you can get one!"];
}
else if(VideoDescription.length > 379 && VideoDescription.length < 410)
{
VideoDescription = [VideoDescription stringByAppendingString:#"\n_______________________________________________"];
VideoDescription = [VideoDescription stringByAppendingString:#"\n\nWant an app like this for your YouTube Channel? Go to www.apps4tubers.com to find out how you can get one!"];
}
else
{
VideoDescription = [VideoDescription stringByAppendingString:#"\n\nFor the best viewing experience, please use WiFi."];
}
CGRect scrollViewFrame = CGRectMake(0, 0, 320, 480);
TheView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
CGSize scrollViewContentSize = CGSizeMake(320, 650);
[TheView setContentSize:scrollViewContentSize];
[TheView setPagingEnabled:NO];
TheView.showsHorizontalScrollIndicator = NO;
TheView.showsVerticalScrollIndicator = YES;
TheView.bounces = NO;
[self.view addSubview:TheView];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
Background = [[UILabel alloc] initWithFrame: CGRectMake(00, 25, 1000, 1600)];
Background.center = CGPointMake(00, 00);
Background.backgroundColor = [self colorWithHexString:#"111625"];
[TheView addSubview: Background];
VideoDecrip = [[UILabel alloc] initWithFrame: CGRectMake(00, 25, 320, 400)];
VideoDecrip.center = CGPointMake(160.5, 400);
VideoDecrip.text = VideoDescription;
VideoDecrip.font = [UIFont fontWithName: #"Cochin-Bold" size: 13.5];
VideoDecrip.textColor = [self colorWithHexString:#"D1E751"];
VideoDecrip.shadowColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.35];
VideoDecrip.layer.shadowOpacity = 0;
VideoDecrip.shadowOffset = CGSizeMake(1,1);
VideoDecrip.layer.masksToBounds = NO;
VideoDecrip.backgroundColor = [UIColor clearColor];
VideoDecrip.textAlignment = NSLineBreakByWordWrapping;
VideoDecrip.adjustsFontSizeToFitWidth = YES;
VideoDecrip.numberOfLines = 0;
[VideoDecrip sizeToFit];
[TheView addSubview: VideoDecrip];
NSLog(#"%i", VideoDecrip.text.length);
VideoTitleBorder = [[UILabel alloc] initWithFrame: CGRectMake(00, 25, 320.5, 30)];
VideoTitleBorder.center = CGPointMake(160, 182.5);
VideoTitleBorder.shadowOffset = CGSizeMake(1,1);
VideoTitleBorder.backgroundColor = [self colorWithHexString:#"0B486B"];
VideoTitleBorder.layer.borderColor = [UIColor darkGrayColor].CGColor;
VideoTitleBorder.layer.borderWidth = .4;
[TheView addSubview: VideoTitleBorder];
VideoTitle = [[UILabel alloc] initWithFrame: CGRectMake(00, 25, 320, 26)];
VideoTitle.text = VidTitle;
if([VideoTitle.text length] < 20)
{
VideoTitle.center = CGPointMake(160, 182.5);
}
else if([VideoTitle.text length] < 30)
{
VideoTitle.center = CGPointMake(160, 182);
}
else
{
VideoTitle.center = CGPointMake(160, 179);
}
VideoTitle.font = [UIFont fontWithName: #"ArialRoundedMTBold" size: 25];
VideoTitle.textColor = [self colorWithHexString:#"BEF202"];
VideoTitle.shadowColor = [UIColor blackColor];
VideoTitle.backgroundColor = [UIColor clearColor];
VideoTitle.shadowOffset = CGSizeMake(1,1);
VideoTitle.textAlignment = NSTextAlignmentCenter;
VideoTitle.adjustsFontSizeToFitWidth = YES;
[TheView addSubview: VideoTitle];
VideoTitleBorder2 = [[UILabel alloc] initWithFrame: CGRectMake(00, 25, 160, 500)];
VideoTitleBorder2.center = CGPointMake(400, 125);
VideoTitleBorder2.shadowOffset = CGSizeMake(1,1);
VideoTitleBorder2.backgroundColor = [self colorWithHexString:#"0B486B"];
VideoTitleBorder2.layer.borderColor = [UIColor darkGrayColor].CGColor;
VideoTitleBorder2.layer.borderWidth = 2.0;
[self.view addSubview: VideoTitleBorder2];
In short, you can use the NSString method -sizeWithFont:forWidth:lineBreakMode: to determine how tall the string will render in a container with the given width and line break mode. You can use that to size your UILabel and to set the scrollview's contentsize appropriately.
Try using sizeToFiton the label, then setting the scrollView's contentSize:
[label sizeToFit];
[scrollView setContentSize:CGSizeMake(CGRectGetWidth(self.view.frame), CGRectGetHeight(label.frame) + 10)];
Using sizeToFit is really nice, just make sure your label is already the right width before you call it.