How to use UIPageControl with iCarousel? - objective-c

I have some images within icarousel. (about 20 images)
I wanna 5 images in a page.
There is no problem about image pixel or image location.
How to use uipagecontrol WITHOUT ScrollView?
ex) able to use some delegate methods.. and so on.
carousel.type = iCarouselTypeLinear;
carousel = [[iCarousel alloc] initWithFrame:CGRectMake(0, 504, 1024, 164)];
carousel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"10004.png"]];
carousel.delegate = self;
carousel.dataSource = self;
[self.view addSubview:carousel];
[carousel reloadData];
[carousel release];
UIView *bandImageView = [[UIView alloc] initWithFrame:CGRectMake(0, 668, 1024, 20)];
bandImageView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"10001.png"]];
[self.view addSubview:bandImageView]; // page dots in
UIPageControl *pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(434, 0, 150, 20);
pageControl.numberOfPages = 6;
pageControl.currentPage = 0;
[bandImageView addSubview:pageControl];
[pageControl release];

In the iCarousel carouselCurrentItemIndexUpdated: delegate method, set
pageControl.currentPage = carousel.currentItemIndex / 5
Then bind your pageControl action to a method like the one below:
- (IBAction)updatePage:(UIPageControl *)pageControl
{
[carousel scrollToItemAtIndex:pageControl.currentPage * 5 aimated:YES];
}
If you're not using a nib file, you can bind the action using
[pageControl addTarget:self action:#selector(updatePage:) forControlEvents:UIControlEventValueChanged];
It's a good idea to set pageControl.defersCurrentPageDisplay = YES; as well to avoid flicker.

Related

lag scrolling scrollview with tableview inside it

I have important problem with UIScrollView.
I want to make one app like yahoo weather and using this source code : BTGlassScrollView
in this source code exist one view with name "foregroundView" that is info view. this info view appear when scrolling my ScrollView from bottom to top.
now I make and add my ScrollView by this code:
_viewScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width + 2*blackSideBarWidth, self.view.frame.size.height)];
[_viewScroller setPagingEnabled:YES];
[_viewScroller setDelegate:self];
[_viewScroller setShowsHorizontalScrollIndicator:NO];
[self.view addSubview:_viewScroller];
_glassScrollView1 = [[BTGlassScrollView alloc] initWithFrame:self.view.frame BackgroundImage:[UIImage imageNamed:#"background3"] blurredImage:nil viewDistanceFromBottom:0 foregroundView:[self customView]];
[_viewScroller addSubview:_glassScrollView1];
in my code I write [self customView] that make me info view and this is customView function:
- (UIView *)customView {
//this method is for make UITableView
[self makeTableBuy:[[self.tableDic objectForKey:#"person"] count]];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _tableBuy.frame.size.width, _tableBuy.frame.size.height)];
view.layer.cornerRadius = 3;
view.backgroundColor = [UIColor colorWithWhite:0 alpha:.3];
[view addSubview:_tableBuy];
return view;
}
- (UITableView*)makeTableBuy:(int)numberOfRow {
_tableBuy = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,numberOfRow*TABLE_HEIGHT) style:UITableViewStyleGrouped];
[_tableBuy setTag:1];
[_tableBuy setBackgroundColor:[UIColor clearColor]];
_tableBuy.showsVerticalScrollIndicator = NO;
_tableBuy.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableBuy.rowHeight = TABLE_HEIGHT;
_tableBuy.scrollEnabled = NO;
_tableBuy.delegate = self;
_tableBuy.dataSource = self;
return _tableBuy;
}
now When I'm scrolling my ScrollView my info view (my tableview) moving to top and appear but my scrolling have so lagging.
please guide me how to fix this lag???

Disable interaction on upper view

I have two views in my program. One is statusView, it's alpha is set to 0.8f. And below it is tableView. How do I disable statusView such way, that clicking on it would not click tableView. Settings userInteractionEnabled = false; didn't help.
Here is how i add views.
[self.view addSubview:_builded.view]; // obj with my tableView
info = [[Info alloc] init];
[self.view addSubview:info.view]; // statusView
If you add a subview like the following, the tableView underneath would not catch the user interaction.
UITableView *testTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
testTableView.delegate = self;
testTableView.dataSource = self;
[self.view addSubview:testTableView];
UIView *statusView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
statusView.backgroundColor = [UIColor redColor];
statusView.alpha = 0.8;
[self.view addSubview:statusView];

Adding UITapGestureRecognizer to UIScrollViews' UIView

I'm developing a Notification Center plugin, and I'm having trouble with UITapGestureRecognizer. I have a UIScrollView, With UIViews acting as a wrapper for my two UILabels in it.
The selector I attached to the UITapGestureRecognizer is never called, and I have no idea why.
EDIT: okay, now it works, but only for the last element in the UIScrollView. I guess it's because I'm using the same UILabel in the loop. What should I do?
- (UIView *)view
{
if (_view == nil)
{
self.aArray = [self.connector refreshData];
_view = [[UIView alloc] initWithFrame:CGRectMake(2, 0, 316, 110)];
//setting the background
UIImage *bg = [[UIImage imageWithContentsOfFile:#"/System/Library/WeeAppPlugins/NCAppline.bundle/WeeAppBackground.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:10];
UIImageView *bgView = [[UIImageView alloc] initWithImage:bg];
bgView.frame = CGRectMake(0, 0, 316, 110);
[_view addSubview:bgView];
//creating the scrollview
UIScrollView *scrView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
UITapGestureRecognizer *linkTappedRec = [[UITapGestureRecognizer alloc]
initWithTarget: self
action: #selector(articleTap:)];
linkTappedRec.numberOfTapsRequired = 1;
linkTappedRec.enabled = YES;
linkTappedRec.cancelsTouchesInView = YES;
//getting the number of pages required
NSInteger viewcount = [self.aArray count]/3;
for (int i = 0; i <viewcount; i++)
{
CGFloat y = i * self.view.frame.size.width;
UILabel *lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 306, 23)];
/* setting bunch of properties */
UILabel *lbl2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 25, 288, 85)];
/* setting bunch of properties */
//this will be the container
UIView *vview = [[UIView alloc] initWithFrame:CGRectMake(y, 0, self.view.frame.size.width, self.view.frame.size.height)];
[vview addSubview:lbl1];
[vview addSubview:lbl2];
vview.tag = i*3+2;
[vview addGestureRecognizer:linkTappedRec];
vview.userInteractionEnabled = YES;
[scrView addSubview:vview];
}
scrView.contentSize = CGSizeMake(self.view.frame.size.width *viewcount, self.view.frame.size.height);
scrView.pagingEnabled = YES;
[_view addSubview:scrView];
}
return _view;
}
- (void)articleTap:(UITapGestureRecognizer *)sender {
NSLog("tap");
}

Using subviews in scrollerview iPhone

I am trying to add uipickerview in uiscrollview, but it is not being shown properly, just a black square.
Further, I have to add 1 more uipickerview, some labels and some buttons.
The code I am using is as under:
-(void)loadView {
[super loadView];
UIPickerView *pView = [[UIPickerView alloc] initWithFrame:CGRectMake(20, 20, 280, 165)];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Background.png"]];
scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroller.pagingEnabled = YES;
NSInteger numberOfViews = 2;
for (int i = 0; i < numberOfViews; i++) {
CGFloat yOrigin = i * self.view.frame.size.height;
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
// awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
[scroller addSubview:awesomeView];
[scroller addSubview:pView];
}
scroller.contentSize = CGSizeMake(self.view.frame.size.width , self.view.frame.size.height * numberOfViews);
[self.view addSubview:scroller];
}
what can be the issue?
Are you putting data in the picker view? I mean, if you just put the picker view without data on it you are not going to see anything on it.
You need to add the delegate and the datasource and put some data in your picker!
pView.delegate = self;
pView.datasource = self;
and then you have to implemente at least:
numberOfComponentsInPickerView:
numberOfRowsInComponent:
titleForRow:
make sure you are implementing uipickerviewdelegate methods. its normal that it will show just the black square because your pickerview cant find the data and thus does not display anything.
UIPickerView *pView = [[UIPickerView alloc] initWithFrame:CGRectMake(20, 20, 280, 165)];
Change height to 216 .. UIPickerView has fixed height of 216 ..only.. you can't change it..

Content change when UIWebView load inside ScrollView

I want to make something like Pulse news when user read the selected news.
When image is not loaded, the space for the image is not yet specified. After the image is loaded, the size of the content also change (the text will be pushed down to make space for the image).
How can i do that?
What i do now is using scroll view, with uiwebview inside it.
- (void)loadView
{
self.view = [[UIView alloc] initWithFrame:CGRectZero];
UIView *thisView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
contentTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 292, 82)];
contentThumbnailWebView = [[UIWebView alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(contentTitleLabel.frame), 292, 0)];
contentDateLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(contentThumbnailWebView.frame), 292, 23)];
playVideoButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(contentThumbnailWebView.frame)/2, CGRectGetMaxY(contentThumbnailWebView.frame)/2, 72, 37)];
[playVideoButton setTitle:#"Play" forState:UIControlStateNormal];
playVideoButton.hidden = YES;
contentSummaryLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(contentDateLabel.frame), 292, 20)];
contentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
contentScrollView.backgroundColor = [UIColor whiteColor];
[thisView addSubview:contentScrollView];
[contentScrollView addSubview:contentDateLabel];
[contentScrollView addSubview:contentTitleLabel];
[contentScrollView addSubview:contentThumbnailWebView];
[contentScrollView addSubview:playVideoButton];
[contentScrollView addSubview:contentSummaryLabel];
//[self.view addSubview:thisView];
self.view = thisView;
contentThumbnailWebView.delegate = self;
}
I've read several topics about this but i still cannot solve it.
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
CGRect frame = aWebView.frame;
frame.size.height = 1;
aWebView.frame = frame;
CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero];
fittingSize.width = aWebView.frame.size.width;
frame.size = fittingSize;
aWebView.frame = frame;
NSLog(#"size: %f, %f", fittingSize.width, fittingSize.height);
[contentDateLabel setFrame:CGRectMake(10, CGRectGetMaxY(aWebView.frame), 292, 23)];
playVideoButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(aWebView.frame)/2, CGRectGetMaxY(aWebView.frame)/2, 72, 37)];
[contentSummaryLabel setFrame:CGRectMake(10, CGRectGetMaxY(contentDateLabel.frame), 292, contentSummaryLabel.frame.size.height )];
contentScrollView.contentSize = CGSizeMake(contentScrollView.frame.size.width, CGRectGetMaxX(contentSummaryLabel.frame));
}
I load jpg image link on it. The image is loaded but the height is not resize correctly. and i also cannot scroll again the scrollView when the webview is loaded.
Below is when i call the image to be loaded
- (void) setImageAsThumbnail:(NSString *)imagehumbnailLink
{
NSURL *imageURL = [NSURL URLWithString:imageThumbnailLink];
NSString *cssString = #"<style type='text/css'>img {width: 292px; height: auto;}</style>";
NSString *myHTMLContent = #"<html><head></head><body><img src='%#'></body></html>";
NSString *htmlString = [NSString stringWithFormat:#"%#%#",cssString,myHTMLContent];
NSString *imageHTML = [[NSString alloc] initWithFormat:htmlString, imageURL];
contentThumbnailWebView.scalesPageToFit = YES;
[contentThumbnailWebView loadHTMLString:imageHTML baseURL:nil];
}
Thank you!
I frequently use UIWebView inside UIScrollView, and because loading HTML is done asynchronously you have to resize the web view and the content size of the scroll view when finished.
[webView sizeThatFits:CGSizeZero]
does not work for me either. Instead, in your webViewDidFinishLoad:(UIWebView*)webView you can measure the size of the HTML document by executing a piece of Javascript:
NSString *js = #"document.getElementById('container').offsetHeight;";
NSString *heightString = [webView stringByEvaluatingJavaScriptFromString:js];
int height = [heightString intValue]; // HTML document height in pixels
In this example, you have to assign the ID 'container' to the top-level element in your HTML (make sure there are no margins around it). This approach works very well for me.