I have a UIView that I have dropped inside of another UIView in IB (iPad version), I am doing this so I can control the background color of the region.
Odd thing is that if I set the background color of the UIView to GroupTableViewBackgroundColor, either in IB or code, the color is always white, it does not respect the color change, nor is it reflected in IB.
Has anyone seen this behavior and found a fix?
Thanks in advance.
I think I know what you are saying. You want the view to be the same as a group table view even though it isn't a group table view. This is what I did:
UITableView *tv = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
UIView *backgroundView = tv.backgroundView;
[self.view addSubview:backgroundView];
[tv release];
CGRect backgroundFrame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[backgroundView setFrame:backgroundFrame];
[self.view sendSubviewToBack:backgroundView];
I am not sure if it is related to your problem but Apple introduced some changes to UITableView for iOS 3.2. They introduced a new property to UITableView defined as follows:
#property (nonatomic, readwrite, retain) UIView *backgroundView;
This new view sits behind the table cells, header and footer which can be confusing if you set the table view background color. As a quick workaround, if you just want to change the color, you can remove the new view:
tableView.backgroundView = nil;
You should then get the same behavior as on the iPhone when you set tableView.backgroundColor. (Of course this may all change with iOS 4.2).
Related
I'm asking since the usual answer, modifying the frame in viewDidLayoutSubviews, does not work - unless you can find a mistake in my code. The frame gets set to the correct width and height, but iOS 7 does not respect the frame.
Currently, the app released long ago looks like this and works on iOS 6 and 7:
https://itunes.apple.com/se/app/eksjo/id435475192?mt=8
Recompiling gives this:
https://www.dropbox.com/s/pzyv2vhtlmlxkoe/Photo%202013-12-11%2009%2047%2030.png
-(void)viewWillAppear:(BOOL)animated {
UIImageView *iv=[[UIImageView alloc] initWithFrame:r(320-102/2,0,102,44)];
iv.image=[UIImage imageNamed:#"Eksjologo5bar.png"];
self.navigationItem.titleView=iv;
[iv release];
}
-(void)viewDidLayoutSubviews {
CGRect frame=self.navigationItem.titleView.frame;
frame.size.width=102;
frame.size.height=44;
self.navigationItem.titleView.frame=frame;
}
All I want to do is put a logo image in the center of the Navigation Bar. I'm looking for a minimum code change to the viewWillAppear code to do this and still be compatible with iOS 6.x.
Edit: It may also be an iOS 6 issue and not an iOS 7 issue. If you can explain why it should be done like in this question, it's an answer to my question: My UINavigationitem's TitleView getting expanded in ios 6
Here is what I do
UIImageView *logoImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, desired_image_width, desired_image_height)];
// if you need to resize the image to fit the UIImageView frame
logoImage.contentMode = UIViewContentModeScaleAspectFit;
// no extension name needed for image_name
[logoImage setImage:[UIImage imageNamed:#"image_name"]];
UIView *logoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, logoImage.frame.size.width, logoImage.frame.size.height)];
[logoView addSubview:logoImage];
self.navigationItem.titleView = logoView;
You may notice that I add the UIImageView instance to an UIView instance before setting the navigationItem's titleView. You may set the UIImageView instance to navigationItem's titleView directly, but the logo will be off center when you navigate to the next page and you still want to show the logo with the back button. The navigation bar will automatically put the UIView in the center, but UIImageView (although UIImageView is a subclass of UIView, I just don't know why).
i hope you will find a solution for my problem, cause i don't have any ideas anymore.
I have a tableview, which has several cells. some cells have another view as subview on their contentView.
This additional view has 2 subviews: 1 UIImageView and 1 UILabel.
Now when i tap an UIButton the UIImageView should be hidden/removed and the UILabel changes it's textColor to white(black before).
The UILabel changes it's textColor but the UIImageView is still visible, even after removing the UIImageView from it's superview.
The Code looks like this.
_adsc_dot_view is the UIImageView
_adsc_text_label is the UILabel
- (void)mc_set_selected:(BOOL)selected {
if (selected) {
_adsc_dot_view.hidden = YES;
_adsc_text_label.textColor = [UIColor whiteColor];
}
else {
_adsc_dot_view.hidden = NO;
_adsc_text_label.textColor = [UIColor blackColor];
}
}
Some check you might find useful for this issue:
1) make sure you create once your UIImageView which referenced as _adsc_dot_view
2) do a debug, mark mc_set_selected with a breakpoint and in the log check the view hierarchy, whether you have the needed number of UIImageView and not more
po [[UIWindow keyWindow] recursiveDescription]
or check this advanced SO answer: I need to inspect the view hierarchy on an iPhone program
3) if you use Interface Builder make sure you have proper type (and not UIImage) and proper reference
You are using UITableView and you add UIImageView and UILabel as a subview in UITableViewCell. So, I think you should reload UITabeView using [self.tableView reloadData]; or [YourTableName reloadData]; after your hide and show UIImageView method. Otherwise you should hide and show UIImageView using UIImageView tag or using UITableViewCell index path.
is the target device on iOS 7? If yes then do try to layoutsubviews of the cell. I had a similar issue where the cell wasn't refreshing on ios 7.
Just reload table view cell after Remove/Hide ImageView.
I am new to iPad developer,
I made one Registration form in my application, when i see my application in Portrait mode,
i am able to see whole form with no scrolling, but when i see same form in Landscape mode, i am not able to see part which is at bottom of page, for that a scrolling should be there to see bottom part.
:
In my .h file when i replace
#interface ReminderPage : UIViewController{
...
...
}
:UIViewController with :UIScrollView
and then when i add label in my .m file like this,
UILabel *Lastpaidlbl = [[[UILabel alloc] initWithFrame:CGRectMake(70 ,400, 130, 50)]autorelease];
Lastpaidlbl.backgroundColor = [UIColor greenColor];
Lastpaidlbl.font=[UIFont systemFontOfSize:20];
Lastpaidlbl.text = #"Lastpaid on :";
[self.view addSubview:Lastpaidlbl];
I am getting error on last line Property view not found on object of type classname.
i am unable to add label in my view.
Any help will be appreciated.
The question appears to be really asking how can all the components on the screen be placed inside a UIScrollView, rather than a UIView. Using Xcode 4.6.3, I found I could achieve this by simply:
In Interface Builder, select all the sub-views inside the main UIView.
Choose Xcode menu item "Editor | Embed In | Scroll View".
The end result was a new scroll view embedded in the existing main UIView, will all the former sub-views of the UIView now as sub-views of the UIScrollView, with the same positioning.
If you want to replace your UIViewController with a UIScrollView, you will have to go a bit of refactoring to your code. The error you get is just an example of that:
the syntax:
[self.view addSubview:Lastpaidlbl];
is correct if self is a UIViewController; since you changed it to be UIScrollView, you should now do:
[self addSubview:Lastpaidlbl];
You will have quite a few changes like this one to make to your code and will face some issues.
Another approach would be this:
instantiate a UIScrollView (not derive from it);
add your UIView (such as you have defined it) to the scroll view;
define the contentSize of the scroll view so to include the whole UIView you have.
The scroll view acts as a container for your existing view (you add your controls to the scroll view, then add the scroll view to self.view); this way, you could integrate it within your existing controller:
1. UIScrollView* scrollView = <alloc/init>
2. [self.view addSubview:scrollView]; (in your controller)
3. [scrollView addSubview:<label>]; (for all of your labels and fields).
4. scrollView.contentSize = xxx;
I think the latter approach will be much easier.
Please put all of your UIComponents to the UIScrollview and then it will start scrolling.
please look in to content size. please change it according to the orientation of device.
You're subclassing UIScrollView, so there is no self.view because already self is the view (of the scrollview). You dont need to subclass the scrollview, you can just embed your components in a ivar scrollview and set its contentSize (in your case, you have to enable the scrolling just when the device is in landscape mode). In interface builder you can embed the selected elements in one click, Editor-> Embed in-> scrollview.
First create scrollview
UIScrollView * scr=[[UIScrollView alloc] initWithFrame:CGRectMake(10, 70, 756, 1000)];
scr.backgroundColor=[UIColor clearColor];
[ self.view addSubview:scr];
second
change [self.view addSubview:Lastpaidlbl];
to
[scr addSubview:Lastpaidlbl];
third
set height depends on content
UIView *view = nil;
NSArray *subviews = [scr subviews];
CGFloat curXLoc = 0;
for (view in subviews)
{
CGRect frame = view.frame;
curXLoc += (frame.size.height);
}
// set the content size so it can be scrollable
[scr setContentSize:CGSizeMake(756, curXLoc)];
Finally
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
self.scr.frame = CGRectMake(0, 0, 703,768);
} else {
self.scr.frame = CGRectMake(0, 0, 768, 1024);
}
return YES;
}
I want to divide the UITableViewCell horizontally into two.
Set the bottom half color to blue and top half color to light blue.
Also the colors need to be reversed when the cell is selected.
I trying to implement using CALayer. But not much successful.
As table contain lots of data use of image will hamper performance and use lot of memory.
How do I do this?
Why not use two UIViews ordered in the background and assign a different background color to each one?
Create two UIView objects and set its background color to the ones that you want. Using these two view, create the background views for selected and normal state of the cell. You do this by setting the frames of the views according to the cell's frame. Then, you need to set two properties for the UITableViewCell in cellForRowAtIndexPath:.
#property(nonatomic, retain) UIView *backgroundView
#property(nonatomic, retain) UIView *selectedBackgroundView
You should be able to use the background view property of the cell
UITableViewCell *cell = // ... code to create table view cell
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0,0,cell.contentView.frame.size.width, cell.contentView.frame.size.height/2);
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0,0,cell.contentView.frame.size.width, cell.contentView.frame.size.height/2);
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0,0,cell.contentView.frame.size.height, cell.contentView.frame.size.width);
[backgroundView addSubview:topView];
[backgroundView addSubview:bottomView];
cell.backgroundView = backgroundView;
This concerns iPhoneOS-sdk-3.2
I am having difficulty changing the border color of a grouped UITableView. I can change the cell background color, separator color, text color, quite easily now, and the rounded corners clip correctly, even when highlighted with whatever colors I have chosen. However the surrounding border remains infuriatingly gray despite many different attempts.
I have read all of the related posts I can find via Google, let alone stackoverflow. I have seen Mike Akers' heroic PITA solution for UITableViewCell clipping -- this problem is solved for iPhoneOS 3.0 and it did not help me with the border.
I have tried both a programmatic and xib-based solution and both provide the same results.
I will share the programmatic version below:
I have a UIViewController subclass rather than a UITableViewController subclass to act as a UITableView delegate -- I chose this route as I am coding on the iPad and UITableViewController reportedly takes over the whole screen. loadView method of my UIViewController subclass:
- (void) loadView {
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[self.view release];
self.view.backgroundColor = [UIColor blackColor];
// add and configure UITableView
CGRect tableViewRect = CGRectMake(0., 0., 256., 768.);
myTableView = [[UITableView alloc] initWithFrame:tableViewRect style:UITableViewStyleGrouped];
// set the tableview delegate to this object and the datasource to the datasource which has already been set
myTableView.delegate = self;
myTableView.dataSource = self;
myTableView.sectionIndexMinimumDisplayRowCount = 1;
myTableView.backgroundColor = [UIColor clearColor];
myTableView.separatorColor = [UIColor whiteColor];
myTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
myTableView.opaque = NO;
// add the table view to our background view
[self.view addSubview:myTableView];
[myTableView release];
}
I found a solution. This behavior does appear to be iPhoneOS 3.2 specific as Apple added a backgroundView property for UITableView in iPhoneOS 3.2.
I tried [myTableView.backgroundView removeFromSuperView] and UITableView just replaced it with another.
Instead, my solution was to add:
myTableView.backgroundView.hidden = YES;