start at the top of the page when changing page - nested

ı have a problem about scrollview.
my project about a newspaper.my problem about : I want to start at the
top of the page when changing page.
scrollview have 8 news.ı want to beginning at the top of the text on
the page when change 2. or 3. or.. news..
please help me about it.because ı need to deliver the project on Monday.for this reason ı
must do today or tomorrow.
code of project in here
myScrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
myScrollview.pagingEnabled = YES;
myScrollview.scrollEnabled =YES;
myScrollview.clipsToBounds = NO;
myScrollview.indicatorStyle = UIScrollViewIndicatorStyleWhite;
myScrollview.showsHorizontalScrollIndicator = YES;
myScrollview.backgroundColor = [UIColor blackColor];
myScrollview.delegate = self;
NSInteger viewcount=4;
NSArray *images = [NSArray arrayWithObjects:[UIImage imageNamed:#"photo1.png"],[UIImage imageNamed:#"photo2.png"],[UIImage imageNamed:#"photo3.png"],[UIImage imageNamed:#"photo4.png"],nil];
for (int i = 0; i <viewcount; i++)
{
CGFloat x = i * self.view.frame.size.width;
subView = [[UIScrollView alloc]initWithFrame:CGRectMake(x, 0, self.view.frame.size.width, self.view.frame.size.height)];
[subView setBackgroundColor:[UIColor blackColor]];
[subView setCanCancelContentTouches:NO];
subView.clipsToBounds = NO; // default is NO, we want to restrict drawing within our scrollview
subView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
aImageView = [[UIImageView alloc ] initWithImage:[images objectAtIndex:i]];
aImageView.frame=CGRectMake(0, 0, 320, 900);
[aImageView setTag:viewcount];
[subView addSubview:aImageView];
[subView setContentSize:CGSizeMake(aImageView.frame.size.width, subView.frame.size.height)];
subView.minimumZoomScale = 1;
subView.maximumZoomScale = 9;
subView.delegate = self;
[subView setScrollEnabled:YES];
subView.contentSize = aImageView.frame.size;
[myScrollview addSubview:subView];
}
myScrollview.contentSize = CGSizeMake(self.view.frame.size.width*viewcount,self.view.frame.size.height);
[self.view addSubview:myScrollview];
https://biliyomusunuz.com

Related

how to get userintraction in uiwebview when added as sub view on a button in ios

I have a button performs some action, have added uiwebview as a sub view of the button to load a small gif animation, I can tap the button to perform the task but I needed to perform the same action when I tap the web view.
-(void)numeritsIphone4{
arrayButtonNames = #[#"Button1.png",#"Button2",#"Button3",#"Button4",#"Button5.png",#"Button6.png",#"Button7.png",#"Button8.png",#"Button9.png",#"Button10.png"];
float y = 20;
int x = 3;
int count = 0;
for (int i = 0 ; i < 10; i++)
{
count ++;
buttonsarray[i] = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonsarray[i].frame = CGRectMake(x, y, 155, 90);
buttonsarray[i].tag = i;
[buttonsarray[i] setBackgroundImage:[UIImage imageNamed:[arrayButtonNames objectAtIndex:i]] forState:UIControlStateNormal];
[buttonsarray[i].titleLabel setFont:[UIFont fontWithName:#"Verdana" size:80]];
[buttonsarray[i] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//buttonsarray[i].titleLabel.textAlignment = UITextAlignmentLeft;
buttonsarray[i].contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[buttonsarray[i] setTitle:[NSString stringWithFormat:#"%d",digit] forState:UIControlStateNormal];
digit ++;
character = [[UIWebView alloc]initWithFrame:CGRectMake(100, 30, 25, 25)];
NSURL *url=[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle]pathForResource:#"Star" ofType:#"gif"]];
character.opaque = NO;
character.backgroundColor = [UIColor clearColor];
character.scrollView.scrollEnabled = NO;
[character loadRequest:[NSURLRequest requestWithURL:url]];
character.userInteractionEnabled = YES;
[buttonsarray[0] addSubview:character];
[character release];
[url release];
[buttonsarray[i] addTarget:self action:#selector(performOperation4:) forControlEvents:UIControlEventTouchUpInside];
x = x + 159;
[self.view addSubview:buttonsarray[i]];
if(count == 2)
{
count = 0;
x = 3;
y = y+ 92;
}
}
A possibility is to add a UITapGestureRecognizer to your UIWebView control and call the same function when the gesture recognizes.
NOTE: This way you have limitation if you have some buttons, links etc on your UIWebView page, that button, links might not get trigger. So give it a try and see if it helps you.

Programmatically showing new window/view when selecting UICollectionViewCell

My code right now for didSelectItemAtIndexPath is the following:
- (void)collectionView:(AFIndexedCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
if(collectionView.index == 0){
NSLog(#"Reordenador contenido por columna %li",indexPath.item);
self.my_data = [self.my_data sortByColumn:indexPath.item skip:1 areAllNumbers:TRUE];
[self.tableView reloadData];
}else{
//show a new window with the content of the cell in a Text Field
NSLog(#"Row = %li; Column = %li - content = %#",collectionView.index,indexPath.item,[self.my_data objectInRow:collectionView.index column:indexPath.item]);
}
}
my_data = custom 2D array class object
How would I programmatically open a new popup window / new view with the content of the selected cell inside, for example, a Text Field, and 2 buttons - Save / Cancel?
Fixed with the following coding:
UIView *mySubView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
[mySubView setBackgroundColor:[UIColor blackColor]];
mySubView.tag = TFIELDSUBVIEW_TAG;
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(2, 10, 300, 80)];
self.textField.borderStyle = UITextBorderStyleRoundedRect;
self.textField.font = [UIFont systemFontOfSize:12];
self.textField.placeholder = [self.the_matrix objectInRow:collectionView.index column:indexPath.item];
self.textField.autocorrectionType = UITextAutocorrectionTypeNo;
self.textField.keyboardType = UIKeyboardTypeDefault;
self.textField.returnKeyType = UIReturnKeyDone;
self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.textField.textAlignment = NSTextAlignmentCenter;
self.textFieldColumn = indexPath.item;
self.textFieldRow = collectionView.index;
UIButton *buttonOK = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonOK.tag = TFIELDSUBVIEW_TAG;
[buttonOK setBackgroundImage:[UIImage imageNamed:#"ok.jpg"] forState:UIControlStateNormal];
[buttonOK addTarget:self
action:#selector(okClicked)
forControlEvents:UIControlEventTouchUpInside];
[buttonOK setTitle:#"" forState:UIControlStateNormal];
buttonOK.backgroundColor = [UIColor grayColor];
buttonOK.frame = CGRectMake(50, 100, 50, 30);
buttonOK.tintColor = [UIColor greenColor];
UIButton *buttonCANCEL = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonCANCEL.tag = TFIELDSUBVIEW_TAG;
[buttonCANCEL addTarget:self
action:#selector(cancelClicked)
forControlEvents:UIControlEventTouchUpInside];
[buttonCANCEL setBackgroundImage:[UIImage imageNamed:#"cancel.jpg"] forState:UIControlStateNormal];
[buttonCANCEL setTitle:#"" forState:UIControlStateNormal];
buttonCANCEL.backgroundColor = [UIColor grayColor];
buttonCANCEL.frame = CGRectMake(120, 100, 75, 30);
buttonCANCEL.tintColor = [UIColor redColor];
[mySubView addSubview:buttonOK];
[mySubView addSubview:buttonCANCEL];
[mySubView addSubview:self.textField];
[self setCustomView:mySubView];
[self.view reloadInputViews];
setCustomView being the following:
-(void) setCustomView:(UIView *)customView {
NSUInteger z = NSNotFound;
if (_customView) {
z = [self.view.subviews indexOfObject:_customView];
}
if (z == NSNotFound) {
[self.view addSubview:customView];
} else {
UIView *superview = _customView.superview;
[_customView removeFromSuperview];
[superview insertSubview:customView atIndex:z];
}
_customView = customView;
}

Xcode :How can I stop video in webview and still using webview

if I use
-(void)viewWillDisappear:(BOOL)animated
{
[subView loadHTMLString:nil baseURL:nil];
}
my Webview can't worked
I try to do this
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
[subView loadHTMLString:nil baseURL:nil];
}
I just want to go next page with paging scrollview and stop video on next page
this my code scrollview paging
book = [[NSMutableArray alloc] initWithObjects:#"page11",#"page12",#"page13",#"page14",#"page15", nil];
for (int i = 0; i < [book count]; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.height * i;
frame.origin.y = 0;
frame.size = CGSizeMake(1024,768);
subView = [[UIWebView alloc] initWithFrame:frame];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[book objectAtIndex:i] ofType:#"html" inDirectory:#""]];
[subView loadRequest:[NSURLRequest requestWithURL:url]];
subView.scalesPageToFit = YES;
[scrollView setBounces:NO];
[scrollView addSubview:subView];
}
scrollView.contentSize = CGSizeMake(1024 * [book count], 768);
[scrollView setFrame:CGRectMake(0, 0, 1024, 768)];
Can I play video and stop on I next page? //Please advice
sorry my English isn't well
You need to load a blank page into the UIWebView to stop the audio:
[self.webView loadRequest:NSURLRequestFromString(#"about:blank")];
or
[self.webView loadHTMLString:#"" baseURL:nil];
Thank for Advice. I try this is works for me
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
for(int i = 0; i < _pageAmount ; i++){
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
[_collectionView cellForItemAtIndexPath:indexPath].backgroundColor = [UIColor clearColor];
}
currentPage = page;
if (currentPage > 0 && currentPage < [book count]-1) {
[[self.scrollView.subviews objectAtIndex:currentPage-1]reload];//
[[self.scrollView.subviews objectAtIndex:currentPage+1]reload];
}
if(self.interfaceOrientation == 1 || self.interfaceOrientation == 2){
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:page inSection:0];
[_collectionView cellForItemAtIndexPath:indexPath].backgroundColor = [UIColor redColor];
}
}

Custom layout on iOS 7 renders element to high

I have a problem with custom layout on iOS 7. Everything appears too high, i.e. under the navigation bar. On iOS 6 it works like a charm even when compiled with iOS 7 SDK.
Below I post code used to init and layout the view. I don't use Interface Builder and I would prefer not to. Any help appreciated.
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.documentTitle = [UITextField new];
self.documentExtension = [UILabel new];
self.documentTitle.attributedPlaceholder = [[NSAttributedString alloc] initWithString:#"Document title"];
self.documentTitle.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 1];
self.documentTitle.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.documentTitle.borderStyle = UITextBorderStyleRoundedRect;
self.documentTitle.returnKeyType = UIReturnKeyDone;
self.documentTitle.keyboardType = UIKeyboardTypeDefault;
self.documentExtension.text = #".pdf";
self.documentExtension.backgroundColor = [UIColor clearColor];
[self addSubview:self.documentTitle];
[self addSubview:self.documentExtension];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
UIEdgeInsets padding = UIEdgeInsetsMake(12, 10, 12, 10);
CGRect layoutRect = UIEdgeInsetsInsetRect(self.bounds, padding);
CGPoint p = layoutRect.origin;
CGSize tmpSize;
CGFloat tfSpaceHorizontal = 6;
CGFloat tfSpaceVertical = 6;
CGSize tmpSizeDocumentExtension = [self.documentExtension sizeThatFits:CGSizeMake(CGRectGetWidth(layoutRect), 1000)];
tmpSize = CGSizeMake(
roundf((CGRectGetWidth(layoutRect) - tfSpaceHorizontal - tmpSizeDocumentExtension.width)),
32
);
self.documentTitle.frame = CGRectMake(
p.x, p.y,
tmpSize.width,
tmpSize.height
);
p.x += tmpSize.width + tfSpaceHorizontal;
CGFloat addedHeight = roundf(tmpSize.height/2 - tmpSizeDocumentExtension.height/2);
addedHeight = addedHeight > 0 ? addedHeight : 0;
p.y += addedHeight;
self.documentExtension.frame = CGRectMake(
p.x,
p.y,
tmpSizeDocumentExtension.width,
tmpSizeDocumentExtension.height
);
}
In iOS 7, every view controller uses full-screen layout, so the coordinate system starts under the status bar, so mind that while positioning your views.
This is mentioned in Apple's iOS 7 UI Transitioning Guide.

resize UIImage in table cell programmatically

how can i resize the UIImage in table cell
cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 5.0;
cell.imageView.frame=CGRectMake(0, 0, 20, 30);
cell.imageView.image =[UIImage imageNamed:#"Diseases.png"];
it is not working
Use this method, pass the size and image, and get the image then show in cell
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
You can also make your custom UITableViewCell, and design as you want to look it
This worked for me.
///////////////////////////////// TO RESIZE IMAGE //////////////////////////////////
////////// FIRST WRITE DESIRED SIZE AND CALL BELOW FINCTION ///////
CGSize newSize ;
newSize.width = 30;
newSize.height = 30;
UIImage *imgSelectedNew = [self imageWithImage:savedImage scaledToSize:newSize];
- (UIImage*)imageWithImage:(UIImage*)sourceImage scaledToSize:(CGSize)targetSize
{
//UIImage *sourceImage = sourceImage;//= self;
UIImage *newImage = nil;
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = targetSize.width;
CGFloat targetHeight = targetSize.height;
CGFloat scaleFactor = 0.0;
CGFloat scaledWidth = targetWidth;
CGFloat scaledHeight = targetHeight;
CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
if (CGSizeEqualToSize(imageSize, targetSize) == NO) {
CGFloat widthFactor = targetWidth / width;
CGFloat heightFactor = targetHeight / height;
if (widthFactor < heightFactor)
scaleFactor = widthFactor;
else
scaleFactor = heightFactor;
scaledWidth = width * scaleFactor;
scaledHeight = height * scaleFactor;
// center the image
if (widthFactor < heightFactor) {
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
} else if (widthFactor > heightFactor) {
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
}
}
// this is actually the interesting part:
UIGraphicsBeginImageContext(targetSize);
CGRect thumbnailRect = CGRectZero;
thumbnailRect.origin = thumbnailPoint;
thumbnailRect.size.width = scaledWidth;
thumbnailRect.size.height = scaledHeight;
[sourceImage drawInRect:thumbnailRect];
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if(newImage == nil)
NSLog(#"could not scale image");
return newImage ;
}
well m also n indorian , Gud to see the other one !!! :)

Resources