iOS customize scrollbar in UITableView - iphone

In iPhone I am going to customize the scrollbar of UITableView with images.
But I didn't find correct method.
Please help me.
Thanks in advance.

firstly you have to uncheck showVerticalIndicatir and showHorizontallIndicatir in the Interface Builder.
then in the ViewDidLoad methode add :
[super viewDidLoad];
self.scrollViewBarImgView = [[UIImageView alloc] init];
UIImage *imgBar = [UIImage imageNamed:#"scroller.png"];
[self.scrollViewBarImgView setImage:imgBar];
CGRect frame = scrollViewBarImgView.frame;
frame.size.width = 8;
frame.size.height = 60;
frame.origin.x = 312;
frame.origin.y = 0;
[self.scrollViewBarImgView setFrame:frame];
[self.tableView addSubview:scrollViewBarImgView];
then in the - (void)scrollViewDidScroll methode :
CGPoint offset = scrollView.contentOffset;
CGRect frame = self.scrollViewBarImgView.frame
float fact = (cellHeight*numberOfRow+ indicatorBarHeight) / tableViewHeight;
frame.origin.y = offset.y + (offset.y/fact);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
[self.scrollViewBarImgView setFrame:frame];
[UIView commitAnimations];

Related

How to add an animation in adding a view?

I have an application in which I had a button on the navigationbar.
When clicking on that I need to add a subview to the self.view.
DemoViewController *demoViewController1 = [[DemoViewController alloc] initWithNibName:#"DemoViewController" bundle:nil];
CGRect frame=demoViewController1.view.frame;
frame.origin.y = -300;
[self.view addSubview:demoViewController1.view];
[UIView animateWithDuration:0.5
animations:^{
CGRect frame1 = frame;
frame1.origin.y = 0;
demoViewController1.view.frame = frame1;
}];
I was tried by setting the frame origin y of the adding view(it is of another view controller).to some negetive value and by clicking bring it to 0.but it doesnt have that drop down effect.
I need to add the view with an animation like drop down view. and when pressed again on the button need to remove also like this.
Can anybody help me on this?
You add the view as subview with a frame that is not on the screen (e.g. negative y coordinate) and modify the frame animated:
MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(50, -200, 200, 200)];
[self.view addSubview:myView];
[UIView animateWithDuration:0.3
animations:^{
CGRect frame = myView.frame;
frame.origin.y = 0;
myView.frame = frame;
}];
And the code for removal:
[UIView animateWithDuration:0.3
animations:^{
CGRect frame = myView.frame;
frame.origin.y = -1 * frame.size.height;
myView.frame = frame;
}
completion:^(BOOL finished) {
[myView removeFromSuperview];
}];
Edit:
Replace your code with this:
DemoViewController *demoViewController1 = [[DemoViewController alloc] initWithNibName:#"DemoViewController" bundle:nil];
CGRect frame=demoViewController1.view.frame;
frame.origin.y = -300;
demoViewController1.view.frame = frame; // You forgot this line
[self.view addSubview:demoViewController1.view];
[UIView animateWithDuration:0.5
animations:^{
CGRect frame1 = demoViewController1.view.frame;
frame1.origin.y = 0;
demoViewController1.view.frame = frame1;
}];
First keep ur view at bottom.
when it's clicked first time
do this
[UIView animateWithDuration:0.3 animations:^{
//keep points that's in a screen
self.view.center = CGPointMake(x,y,width,height);
}];
when it's clicked second time
give points below the visible screen
[UIView animateWithDuration:0.3 animations:^{
//keep points that's in a screen
self.view.center = CGPointMake(x,y,width,height);
}];
Let me know if you find a better way than this.
[self.yourView setFrame:setYourInitialFrame];
[UIView animateWithDuration: 1.00 animations:^{
[self.yourView setFrame:setYourFinalFrame];
}];

Customize Scrolling indicator

Is there a way to customize scrolling indicator(vertical or horizontal) in UIScrollView. For example, change it's color or position in scrollview.
First, you have to uncheck showVerticalIndicator and showHorizontallIndicator in the Interface Builder.
Then in the viewDidLoad method add :
[super viewDidLoad];
self.scrollViewBarImgView = [[UIImageView alloc] init];
UIImage *imgBar = [UIImage imageNamed:#"scroller.png"];
[self.scrollViewBarImgView setImage:imgBar];
CGRect frame = scrollViewBarImgView.frame;
frame.size.width = 8;
frame.size.height = 60;
frame.origin.x = 312;
frame.origin.y = 0;
[self.scrollViewBarImgView setFrame:frame];
[self.tableView addSubview:scrollViewBarImgView];
then in the - (void)scrollViewDidScroll method :
CGPoint offset = scrollView.contentOffset;
CGRect frame = self.scrollViewBarImgView.frame;
float fact = (cellHeight*numberOfRow+ indicatorBarHeight) / tableViewHeight;
frame.origin.y = offset.y + (offset.y/fact);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
[self.scrollViewBarImgView setFrame:frame];
[UIView commitAnimations];
This is working for me.

How to use CGAffineTransformMakeRotation for NSString

I want to use CGAffineTransformMakeRotation for NSString, how can i do it? Its working with labels and i need for my function only strings.
CGAffineTransformMakeRotation is used to set the transform property of a UIView, NSString is not a UIView so it cant be transformed, it has not concept of rotation
you need to do this at display time with a UILabel
an example:
NSString *myString = #"whatever";
CGAffineTransform stringTransform = CGAffineTransformMakeRotation(M_PI / 2.0f);
UILabel *stringLabel = [[UILabel alloc] initWithFrame:labelFrame];
stringLabel.transform = stringTransform;
stringLabel.text = myString;
[self.view addSubview:stringLabel];
You can rotate text label like below code:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib
label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
label.text = #"fof fof fof";
[self.view addSubview:label];
}
- (IBAction)rotate:(id)sender {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(endAnimation)];
CGAffineTransform rotate = CGAffineTransformMakeRotation(90.0f * (M_PI / 180.0f));
label.transform = rotate;
[UIView commitAnimations];
}

How to slide a UIView right above a UITabBar

I have a UIView that I want to slide from behind a UITabBar to be position right on top of it.
This doesn't work. My view does not appear.
- (void)showNotificationBar
{
CGRect frame = CGRectMake(0, 500, 320, 32);
frame.origin.y = CGRectGetMaxY(self.parentViewController.tabBarController.tabBar.frame) - frame.size.height;
notificationBar.frame = frame;
[self.parentViewController.tabBarController.tabBar.superview insertSubview:notificationBar
belowSubview:self.parentViewController.tabBarController.tabBar];
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = notificationBar.frame;
frame.origin.y = CGRectGetMaxY(self.parentViewController.tabBarController.tabBar.frame);
notificationBar.frame = frame;
}];
}
Initialize frame.origin.y like this:
frame.origin.y = self.tabBarController.tabBar.frame.origin.y;
In the animations block, set it like this:
frame.origin.y -= frame.size.height;
If you want it to show in every view, you could do to things: either show it at the bottom of every view or show it in the application's window. I personally like this second approach better because it helps avoiding duplicate code:
CGFloat notificationBarHeight = 40.0f;
UIView *notificationBar = [[UILabel alloc]initWithFrame:CGRectMake(0, self.tabBarController.tabBar.frame.origin.y - notificationBarHeight, 320, notificationBarHeight)];
[self.window insertSubview:notificationBar atIndex:[[self.window subviews]count]];
[self.view insertSubview:notificationView atIndex:1]; worked for me...

iPhone: TableView inside UIScrollview, show vaccillating scrollbars around

I have added some table and other vies in a scrollview. scrolling in tables are working fine. But in the parent scrollview, when scrolling, a vacillating vertical scrollbars are shown, sometimes it even come to the middle of the screen. sometime show at the left side of the screen. and not limited to the vertical scrollbar region. When I set the showsVerticalScrollIndicator = NO, it is not shown. But do you know why the scrollbar is moving around.
DashboardView is a subclass of UIScrollView.
dashboard=[[DashboardView alloc] initWithFrame:fullScreenRect];
dashboard.contentSize = CGSizeMake(320,700); // must do!
dashboard.showsVerticalScrollIndicator = YES;
dashboard.bounces = YES;
self.view = dashboard;
#implementation DashboardView
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect {
// Drawing code
}
- (void) layoutSubviews{
NSArray *views = self.subviews;
[UIView beginAnimations:#"CollapseExpand" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
UIView *view = [views objectAtIndex: 0];
CGRect rect = view.frame;
for (int i = 1; i < [views count]; i++ ) {
view = [views objectAtIndex:i];
view.frame = CGRectMake(rect.origin.x, rect.origin.y + rect.size.height, view.frame.size.width, view.frame.size.height);
rect = view.frame;
}
[UIView commitAnimations];
}
Remember that scrollbars is subviews of scroll too. Exclude it from views array, before doing something with views.
Yap. that solved my problem. It seems Scrollbars are a kind of UIImageView. If anybody need it, this is my new code which works fine.
(void) layoutSubviews{
NSArray *views = self.subviews;
[UIView beginAnimations:#"CollapseExpand" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
// [self.view insertSubview:balanceView belowSubview:profileView];
UIView *view = [views objectAtIndex: 0];
CGRect rect = view.frame;
for (int i = 1; i < [views count]; i++ ) {
view = [views objectAtIndex:i];
if ([view isMemberOfClass: [UIView class] ]) {
//CFShow(view);
view.frame = CGRectMake(rect.origin.x, rect.origin.y + rect.size.height, view.frame.size.width, view.frame.size.height);
rect = view.frame;
}
}
[UIView commitAnimations];
}