Im using the following code to get the effect similar to that of the android like progress:
-(void) showSpinner
{
NSLog(#"as");
loadingView = [[UIView alloc] initWithFrame:CGRectMake(100, 300, 170, 170)];
loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
loadingView.clipsToBounds = YES;
loadingView.layer.cornerRadius = 10.0;
activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.frame = CGRectMake(65, 40, activityView.bounds.size.width, activityView.bounds.size.height);
[loadingView addSubview:activityView];
loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 115, 130, 22)];
loadingLabel.backgroundColor = [UIColor clearColor];
loadingLabel.textColor = [UIColor whiteColor];
loadingLabel.adjustsFontSizeToFitWidth = YES;
loadingLabel.textAlignment = NSTextAlignmentCenter;
loadingLabel.text = #"Loading...";
[loadingView addSubview:loadingLabel];
loadingView .center = CGPointMake(CGRectGetWidth(self.view.frame) / 2, CGRectGetHeight(self.view.frame) / 2);
[self.statutoryTbl addSubview:loadingView];
[activityView startAnimating];
}
The issue is that the UILabel appears below the spinner. I want it to be nearby spinner and the loadingview to be wide as android. What am I missing in my code?
Initialise your loadingLabel with this code:
loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake([activityView frame].origin.x+[activityView frame].size.width+20, 10, [loadingView frame].size.width-([activityView frame].origin.x+[activityView frame].size.width+20)-10, [loadingView frame].size.height-20)];
Related
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.
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.
I have a UIScrollView and inside this Scroll View i have some controls. Specifically a label thats underlined and i have setup Tap Gesture for the UILabel but doesn't seem to fire the methods that the Tap Gesture is bound to.
Here is the code:
-(void)setupUserNameControls:(UIScrollView*)scroll{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 23, 70, 16)];
label.textColor = [UIColor colorWithRed:59.0f/255 green:59.0f/255 blue:59.0f/255 alpha:1.0f];
label.text = #"First Name";
label.font = [UIFont fontWithName:#"Helvetica" size:14];
[scroll addSubview:label];
UIView *textView = [[UIView alloc] initWithFrame:CGRectMake(88, 16, 215, 28)];
textView.backgroundColor = [UIColor colorWithRed:60.0f/255 green:59.0f/255 blue:59.0f/255 alpha:1.0f];
[scroll addSubview:textView];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(15, 55, 70, 16)];
label2.textColor = [UIColor colorWithRed:59.0f/255 green:59.0f/255 blue:59.0f/255 alpha:1.0f];
label2.text = #"Last Name";
label2.font = [UIFont fontWithName:#"Helvetica" size:14];
[scroll addSubview:label2];
UIView *textView2 = [[UIView alloc] initWithFrame:CGRectMake(88, 48, 215, 28)];
textView2.backgroundColor = [UIColor colorWithRed:60.0f/255 green:59.0f/255 blue:59.0f/255 alpha:1.0f];
[scroll addSubview:textView2];
UIImageView *imageViewSep = [[UIImageView alloc] initWithFrame:CGRectMake(10, 92, 300, 2)];
UIImage *imageSep = [UIImage imageNamed:#"seperator.png"];
imageViewSep.image = imageSep;
[scroll addSubview:imageViewSep];
UIView *viewImage = [[UIView alloc] initWithFrame:CGRectMake(10, 108, 58, 58)];
viewImage.backgroundColor = [UIColor colorWithRed:132.0f/255 green:132.0f/255 blue:132.0f/255 alpha:1.0f];
[scroll addSubview:viewImage];
UIImageView *imageViewUser = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 48, 48)];
UIImage *imageUser = [UIImage imageNamed:#"defaultuser.jpg"];
imageViewUser.image = imageUser;
[viewImage addSubview:imageViewUser];
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:#"Click to select your user image"];
[attributeString addAttribute:NSUnderlineStyleAttributeName
value:[NSNumber numberWithInt:1]
range:(NSRange){0,[attributeString length]}];
UILabel *labelPickImage = [[UILabel alloc] initWithFrame:CGRectMake(88, 126, 215, 16)];
labelPickImage.numberOfLines = 0;
labelPickImage.textColor = [UIColor colorWithRed:59.0f/255 green:59.0f/255 blue:59.0f/255 alpha:1.0f];
labelPickImage.attributedText = attributeString;
labelPickImage.font = [UIFont fontWithName:#"Helvetica" size:14];
[scroll addSubview:labelPickImage];
UITapGestureRecognizer *userImageTextTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(userImageSelectTap:)];
[userImageTextTap setNumberOfTouchesRequired:1];
[userImageTextTap setNumberOfTapsRequired:1];
[labelPickImage addGestureRecognizer:userImageTextTap];
}
-(void)userImageSelectTap:(UIGestureRecognizer *)sender{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}else{
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *) Picker {
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
This is how i set up the UIScrollView and pass it in:
UIScrollView *userInfoScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 108, screenRect.size.width, screenRect.size.height - 40 - viewTop.bounds.size.height - viewTopBorder.bounds.size.height)];
[userInfoScrollView setBackgroundColor:[UIColor colorWithRed:228.0f/255 green:228.0f/255 blue:228.0f/255 alpha:1.0f]];
userInfoScrollView.userInteractionEnabled = YES;
[self.viewUser addSubview:userInfoScrollView];
make sure the label stays in front of the scrollView.
[scroll bringSubviewToFront:labelPickImage];
Also,
labelPickImage.userInteractionEnabled = YES;
Why won't my UIView (created below) show up in the UITableViewHeader that I try to add it to?
UIView *view = [[UIView alloc] initWithFrame: CGRectMake ( 20, 20, 400, 400)];
searchBar = (UISearchBar *)self.tableView.tableHeaderView;
[searchBar.subviews objectAtIndex:0] removeFromSuperview];
searchBar.backgroundColor = [UIColor clearColor];
[view addSubview:searchBar];
self.tableView.tableHeaderView = nil;
view.backgroundColor = [UIColor redColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, self.view.frame.size.width, 60)];
label.shadowColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:.35];
label.shadowOffset = CGSizeMake(0, -1.0);
label.text = #"188 People";
label.textColor = [UIColor grayColor];
label.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:12.0];
label.backgroundColor = [UIColor clearColor];
[view addSubview:label];
self.tableView.tableHeaderView = view;
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame: CGRectMake ( 20, 20, 400, 400)];
searchBar = (UISearchBar *)self.tableView.tableHeaderView;
[searchBar.subviews objectAtIndex:0] removeFromSuperview];
searchBar.backgroundColor = [UIColor clearColor];
[view addSubview:searchBar];
view.backgroundColor = [UIColor redColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, self.view.frame.size.width, 60)];
label.shadowColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:.35];
label.shadowOffset = CGSizeMake(0, -1.0);
label.text = #"188 People";
label.textColor = [UIColor grayColor];
label.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:12.0];
label.backgroundColor = [UIColor clearColor];
[view addSubview:label];
return view;//Please note the header will look the same for each section. You can add a switch or if/else to augment this
}
-As a side note, if you're planning on using the label here to set the text for the header, I suggest looking into the following methods:
-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
I am adding some dynamic UIView named as *cellSeparator and other UILabels...now what happen is when i again call this code then its rewrite the label text and overwrite on previously created label text...i am not very much aware to this ios development.so can anyone please tell me how can i remove this UIView dynamically before creating again?beacause UIView is dynamically created i dont know how to remove that UIview
UILabel *indexLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-150, self.view.frame.size.width/2,30)];
[indexLabel setBackgroundColor:[UIColor clearColor]];
indexLabel.textColor = [UIColor whiteColor];
indexLabel.text = #"Details:-";
indexLabel.font = [UIFont systemFontOfSize:20.00];
UILabel *tagLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-120, self.view.frame.size.width/2, 30)];
tagLabel.backgroundColor = [UIColor clearColor];
NSLog(#"LOg %#",imageId);
NSLog(#"LOg %#",imageStyle);
NSLog(#"LOg %#",imageType);
NSLog(#"LOg %#",imageWeight);
tagLabel.text = [NSString stringWithFormat:#"The Id of Jewl Is: %#",imageId];
imageTypelabel= [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-90, self.view.frame.size.width/2, 30)];
imageTypelabel.backgroundColor = [UIColor clearColor];
imageTypelabel.text = [NSString stringWithFormat:#"The Type of Jewl Is: %#",imageType];
imageStylelabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-60, self.view.frame.size.width/2, 30)];
imageTypelabel.backgroundColor = [UIColor clearColor];
imageStylelabel.text = [NSString stringWithFormat:#"The style of Jewl Is: %#",imageStyle];
imageWeightlabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-30, self.view.frame.size.width/2, 30)];
imageStylelabel.backgroundColor = [UIColor clearColor];
imageWeightlabel.text = [NSString stringWithFormat:#"The weight of Jewl Is: %#",imageWeight];
imageWeightlabel.backgroundColor = [UIColor clearColor];
imageWeightlabel.textColor = [UIColor whiteColor];
imageTypelabel.textColor = [UIColor whiteColor];
imageWeightlabel.textColor = [UIColor whiteColor];
tagLabel.textColor = [UIColor whiteColor];
UIImage *imageBegin = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:imageBegin];
UIView *cellSeparator = [[UIView alloc] initWithFrame:CGRectMake(0,545, self.view.frame.size.width ,3)];
cellSeparator.tag=1;
[cellSeparator setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleWidth];
[cellSeparator setContentMode:UIViewContentModeTopLeft];
[cellSeparator setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview:cellSeparator];
You could write a method to remove all the subviews of the view and modify this code according to your need.
- (void)removeSubviewsOfView
{
NSArray *subViews = [self.view subviews];
for(UIView *view in subViews)
{
[view removeFromSuperview];
}
}