Show screen on external display - ios5

I look at some examples at Github, but all of them were without storyboard usage.
I tried to use that code in my app, but all I see on external device in simulator is black screen.
Code I have now:
if([[UIScreen screens]count] > 1) {
CGSize maxSize;
UIScreenMode *maxScreenMode;
for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
{
UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
if(current.size.width > maxSize.width)
{
maxSize = current.size;
maxScreenMode = current;
}
}
UIScreen *externalScreen = [[UIScreen screens] objectAtIndex:1];
externalScreen.currentMode = maxScreenMode;
[self myScreenInit:externalScreen];
}
- (void) screenDidConnect:(NSNotification *)notification {
[self myScreenInit:[notification object]];
}
- (void) myScreenInit:(UIScreen *)connectedScreen {
CGRect frame = connectedScreen.bounds;
UIWindow *window = [[UIWindow alloc] initWithFrame:frame];
window.backgroundColor = [UIColor whiteColor];
[window setScreen:connectedScreen];
window.hidden = NO;
}

If you want to see more than a black screen you'll need to put in some content. One option would be to add something like this:
UIView *myCustomUIView = [[MyCustomUIView alloc] initWithFrame:frame];
[window addSubview:myCustomUIView];
Then draw stuff in the view's drawRect:(CGRect) method.
Hope this helps.

Related

How to customize paging in UIScrollView?

I have a question in scroll view.
Right now I wrote a sample about image gallery with scroll view. I have plenty of images added into a scroll view. Each time, it display 3 images, the question is how can measure the scrolling properly. For example: the minimum each scroll is moving 1 image. Right now, I think each time I scroll, the minimum images moving are 3. That make me can't stop at the right image I want to see.
Below is the code.
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scroll subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (kScrollObjWidth);
}
}
// set the content size so it can be scrollable
[scroll setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scroll bounds].size.height)];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// 1. setup the scrollview for multiple images and add it to the view controller
//
// note: the following can be done in Interface Builder, but we show this in code for clarity
[scroll setBackgroundColor:[UIColor blackColor]];
[scroll setCanCancelContentTouches:NO];
scroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scroll.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scroll.scrollEnabled = YES;
// pagingEnabled property default is NO, if set the scroller will stop or snap at each photo
// if you want free-flowing scroll, don't set this property.
scroll.pagingEnabled = YES;
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:#"image%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i; // tag our images for later use when we place them in serial fashion
[scroll addSubview:imageView];
[imageView release];
}
[self layoutScrollImages];
}
Use this code......
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(scroll.contentOffset.y> 320)
{
int y = scrollView.contentOffset.y;
y = y/3;
[scrollView setContentOffset:CGPointMake(0, y)];
}
}
Hope, this will help you...Chill
Subclass the content view and overwrite this function:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if ([self pointInside:point withEvent:event]) {
if ([[self subviews] count] > 0) {
//force return of first child, if exists
return [[self subviews] objectAtIndex:0];
} else {
return self;
}
}
return nil; }
See detail at https://github.com/taufikobet/ScrollViewCustomPaging.

UIScrollview with multiple images and pinch to zoom

I am trying to duplicate the Photos app on the iPhone. Meaning, a scrollview with multiple images, and each image can be pinched to zoom in/out.
The Apple ScrollViewSuite example code only deals with 1 image inside of a scrollview. I have found that with multiple images, scrolling through the images becomes unpredictable. Also, the view becomes uncentered after pinching to zoom.
I have found this on Stack Overflow: Zoom UIScrollView with multiple images
However, what am I supposed to write in the scrollview delegate functions?
This is what I found to work. Supports multiple images with paging and zooming. Enjoy!
#define VIEW_FOR_ZOOM_TAG (1)
#implementation SVViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *mainScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
mainScrollView.pagingEnabled = YES;
mainScrollView.showsHorizontalScrollIndicator = NO;
mainScrollView.showsVerticalScrollIndicator = NO;
CGRect innerScrollFrame = mainScrollView.bounds;
for (NSInteger i = 0; i < 3; i++) {
UIImageView *imageForZooming = [[UIImageView alloc] initWithImage:[UIImage imageNamed:
[NSString stringWithFormat:#"page%d", i + 1]]];
imageForZooming.tag = VIEW_FOR_ZOOM_TAG;
UIScrollView *pageScrollView = [[UIScrollView alloc] initWithFrame:innerScrollFrame];
pageScrollView.minimumZoomScale = 1.0f;
pageScrollView.maximumZoomScale = 2.0f;
pageScrollView.zoomScale = 1.0f;
pageScrollView.contentSize = imageForZooming.bounds.size;
pageScrollView.delegate = self;
pageScrollView.showsHorizontalScrollIndicator = NO;
pageScrollView.showsVerticalScrollIndicator = NO;
[pageScrollView addSubview:imageForZooming];
[mainScrollView addSubview:pageScrollView];
if (i < 2) {
innerScrollFrame.origin.x += innerScrollFrame.size.width;
}
}
mainScrollView.contentSize = CGSizeMake(innerScrollFrame.origin.x +
innerScrollFrame.size.width, mainScrollView.bounds.size.height);
[self.view addSubview:mainScrollView];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [scrollView viewWithTag:VIEW_FOR_ZOOM_TAG];
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate {
return NO;
}
#end

Window subview not rotating after orientation of the device changes

I'm creating an UIView with a label inside AppDelegate and displaying it like this:
[window addSubview:self.roundedCornerView];
Problem is when I rotate the device the view with label don't rotate at all. The text in the label is in wrong orientation as well. Window in my application got another subview which is the UIViewControllers subview and it is rotating fine.
Do I need to create another UIViewController in my AppDelegate and attach created view to it, then subclassing it and allowing for interface orientation in order to get roundedCornerView to rotate?
UPDATE
Ok I've tried to do this by creating new ViewController and sublcassing it here is code in my AppDelegate:
ActivityIndicatorWithLabelViewController *aiWithLabel = [[[ActivityIndicatorWithLabelViewController alloc] init] autorelease];
aiWithLabel.textOfTheLabel = text;
[window addSubview:aiWithLabel.view];
The ActivityIndicatorWithLabelViewController class is visible here:
//
// ActivityIndicatorWithLabelViewController.m
// LOFT
//
// Created by Marcin Zyga on 15.11.2011.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "ActivityIndicatorWithLabelViewController.h"
#implementation ActivityIndicatorWithLabelViewController
#synthesize roundedCornerView;
#synthesize textActivityIndicatorLabel;
#synthesize textOfTheLabel;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
UIActivityIndicatorView *mainApplicationActivityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
mainApplicationActivityIndicatorView.frame = CGRectMake(80, 80, 40, 40);
mainApplicationActivityIndicatorView.hidesWhenStopped = YES;
//self.roundedCornerView = [[[UIView alloc] initWithFrame:CGRectMake(280, 400, 200, 200)] autorelease];
self.roundedCornerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)] autorelease];
roundedCornerView.backgroundColor = [UIColor blackColor];
roundedCornerView.alpha = 0.9f;
roundedCornerView.layer.cornerRadius = 12.0;
[roundedCornerView addSubview:mainApplicationActivityIndicatorView];
[mainApplicationActivityIndicatorView startAnimating];
// self.roundedCornerView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
//self.roundedCornerView.autoresizesSubviews = YES;
self.textActivityIndicatorLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, 200, 50)];
self.textActivityIndicatorLabel.backgroundColor = [UIColor clearColor];
self.textActivityIndicatorLabel.textAlignment = UITextAlignmentCenter;
self.textActivityIndicatorLabel.textColor = [UIColor whiteColor];
self.textActivityIndicatorLabel.font = [UIFont systemFontOfSize:22];
self.textActivityIndicatorLabel.text = #"";
// self.textActivityIndicatorLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
[self.roundedCornerView addSubview:textActivityIndicatorLabel];
self.textActivityIndicatorLabel.text = textOfTheLabel;
self.view.frame = CGRectMake(280, 400, 200, 200);
[self.view addSubview:self.roundedCornerView];
//self.view = self.roundedCornerView;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
[self.textActivityIndicatorLabel removeFromSuperview];
[self.textActivityIndicatorLabel release];
self.textActivityIndicatorLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
self.textActivityIndicatorLabel.backgroundColor = [UIColor clearColor];
self.textActivityIndicatorLabel.textAlignment = UITextAlignmentCenter;
self.textActivityIndicatorLabel.textColor = [UIColor whiteColor];
self.textActivityIndicatorLabel.font = [UIFont systemFontOfSize:22];
self.textActivityIndicatorLabel.text = #"Landscape";
[self.roundedCornerView addSubview:textActivityIndicatorLabel];
NSLog(#"LANDSCAPE");
}
NSLog(#"ENTERING SUPPORTED ORIENTATION!");
return YES;
}
#end
As you see there is some debug code in here. When I'm rotating the device from potrait to landscape I get ENTERING SUPPORTE ORIENTATION! as well as LADNSCAPE NSLog. Removing label is working fine, but when I'm adding new one it is still presented (the text) in wrong orientation. What I am doing wrong?
UIWindow should only have one subview which defines the root UIViewController. I believe that UIWindow only forwards rotation events to its first subview.
Create a single container UIView and move your subviews into it.
Solution is follow below steps :
In subView's .m file add code on top of interface of you view:
typedef NS_OPTIONS(NSUInteger, AGInterfaceOrientationMask) {
AGInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
AGInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
AGInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
AGInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
AGInterfaceOrientationMaskLandscape = (AGInterfaceOrientationMaskLandscapeLeft | AGInterfaceOrientationMaskLandscapeRight),
AGInterfaceOrientationMaskAll = (AGInterfaceOrientationMaskPortrait | AGInterfaceOrientationMaskLandscapeLeft | AGInterfaceOrientationMaskLandscapeRight | AGInterfaceOrientationMaskPortraitUpsideDown),
AGInterfaceOrientationMaskAllButUpsideDown = (AGInterfaceOrientationMaskPortrait | AGInterfaceOrientationMaskLandscapeLeft | AGInterfaceOrientationMaskLandscapeRight),
}
In subView's .m file add code
#pragma mark - Orientation
- (void)statusBarFrameOrOrientationChanged:(NSNotification *)notification
{
/*
This notification is most likely triggered inside an animation block,
therefore no animation is needed to perform this nice transition.
*/
[self rotateAccordingToStatusBarOrientationAndSupportedOrientations];
}
- (void)rotateAccordingToStatusBarOrientationAndSupportedOrientations
{
UIInterfaceOrientation orientation = [self desiredOrientation];
CGFloat angle = [self UIInterfaceOrientationAngleOfOrientation:orientation];
CGFloat statusBarHeight = [[self class] getStatusBarHeight];
UIInterfaceOrientation statusBarOrientation = [UIApplication sharedApplication].statusBarOrientation;
CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
CGRect frame = [[self class] rectInWindowBounds:self.view.window.bounds statusBarOrientation:statusBarOrientation statusBarHeight:statusBarHeight];
[self setIfNotEqualTransform:transform frame:frame];
CGRect rect = btnClose.frame;
rect.origin.x = (subView.frame.origin.x+subView.frame.size.width)-(rect.size.width/2);
rect.origin.y = subView.frame.origin.y-(rect.size.height/2);
btnClose.frame = rect;
}
- (void)setIfNotEqualTransform:(CGAffineTransform)transform frame:(CGRect)frame
{
if(!CGAffineTransformEqualToTransform(self.view.transform, transform))
{
self.view.transform = transform;
}
if(!CGRectEqualToRect(self.view.frame, frame))
{
self.view.frame = frame;
}
}
+ (CGFloat)getStatusBarHeight
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if(UIInterfaceOrientationIsLandscape(orientation))
{
return [UIApplication sharedApplication].statusBarFrame.size.width;
}
else
{
return [UIApplication sharedApplication].statusBarFrame.size.height;
}
}
static BOOL IS_BELOW_IOS_7()
{
static BOOL answer;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
answer = [[[UIDevice currentDevice] systemVersion] floatValue] < 7.0;
});
return answer;
}
+ (CGRect)rectInWindowBounds:(CGRect)windowBounds statusBarOrientation:(UIInterfaceOrientation)statusBarOrientation statusBarHeight:(CGFloat)statusBarHeight
{
CGRect frame = windowBounds;
if(IS_BELOW_IOS_7())
{
frame.origin.x += statusBarOrientation == UIInterfaceOrientationLandscapeLeft ? statusBarHeight : 0;
frame.origin.y += statusBarOrientation == UIInterfaceOrientationPortrait ? statusBarHeight : 0;
frame.size.width -= UIInterfaceOrientationIsLandscape(statusBarOrientation) ? statusBarHeight : 0;
frame.size.height -= UIInterfaceOrientationIsPortrait(statusBarOrientation) ? statusBarHeight : 0;
}
return frame;
}
- (UIInterfaceOrientation)desiredOrientation
{
UIInterfaceOrientation statusBarOrientation = [[UIApplication sharedApplication] statusBarOrientation];
AGInterfaceOrientationMask statusBarOrientationAsMask = [self AGInterfaceOrientationMaskFromOrientation:statusBarOrientation];
if(self.supportedInterfaceOrientations & statusBarOrientationAsMask)
{
return statusBarOrientation;
}
else
{
if(self.supportedInterfaceOrientations & AGInterfaceOrientationMaskPortrait)
{
return UIInterfaceOrientationPortrait;
}
else if(self.supportedInterfaceOrientations & AGInterfaceOrientationMaskLandscapeLeft)
{
return UIInterfaceOrientationLandscapeLeft;
}
else if(self.supportedInterfaceOrientations & AGInterfaceOrientationMaskLandscapeRight)
{
return UIInterfaceOrientationLandscapeRight;
}
else
{
return UIInterfaceOrientationPortraitUpsideDown;
}
}
}
-(CGFloat)UIInterfaceOrientationAngleOfOrientation:(UIInterfaceOrientation)orientation
{
CGFloat angle;
switch (orientation)
{
case UIInterfaceOrientationPortraitUpsideDown:
angle = M_PI;
break;
case UIInterfaceOrientationLandscapeLeft:
angle = -M_PI_2;
break;
case UIInterfaceOrientationLandscapeRight:
angle = M_PI_2;
break;
default:
angle = 0.0;
break;
}
return angle;
}
-(AGInterfaceOrientationMask)AGInterfaceOrientationMaskFromOrientation:(UIInterfaceOrientation)orientation
{
return 1 << orientation;
}
//If dealloc is a duplicate method then remove this dealloc method and add the unregisterFromNotifications method in dealloc.
- (void)dealloc {
[self unregisterFromNotifications];
}
-(void)unregisterFromNotifications
{
//for orientation
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
}
Also In subView's .h file add this line.
- (void)rotateAccordingToStatusBarOrientationAndSupportedOrientations;
Now time to use above added code for orientation change in subview.
While adding subview in window or self.view like this :
[objAppDelegate.window addSubview:objViewController.view];
//added this method to rotate subview according to orientation when added
[objViewController rotateAccordingToStatusBarOrientationAndSupportedOrientations];
Reference taken from AGWindowView
Window subviews don't rotate by themselves, they usually rotate with the help of a view controller.
You could either add the views you want rotated to a view controller and then add that to the window, or you could register for device orientation changes notifications and rotate them yourself.

Is there a way to change page indicator dots color

I am newbie to iphone programming, I am trying to develop an app which uses page control. My view's background color is white and page controllers default one is also white, which makes page control invisible on my view so I have changed the back ground color of page control to make is visible. Now, the view appears patched and bad. Is there a way to change just the dots color for page control?
Thanks in advance
We customized the UIPageControl to use a custom image for the page indicator, I have listed the guts of the class below...
GrayPageControl.h
#interface GrayPageControl : UIPageControl
{
UIImage* activeImage;
UIImage* inactiveImage;
}
GrayPageControl.m
-(id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
activeImage = [[UIImage imageNamed:#"active_page_image.png"] retain];
inactiveImage = [[UIImage imageNamed:#"inactive_page_image.png"] retain];
return self;
}
-(void) updateDots
{
for (int i = 0; i < [self.subviews count]; i++)
{
UIImageView* dot = [self.subviews objectAtIndex:i];
if (i == self.currentPage) dot.image = activeImage;
else dot.image = inactiveImage;
}
}
-(void) setCurrentPage:(NSInteger)page
{
[super setCurrentPage:page];
[self updateDots];
}
Then in the View Controller we just use it like a normal UIPageControl
IBOutlet GrayPageControl* PageIndicator;
Edit:
In the view controller that has the GrayPageControl I have an IBAction that is linked to the GrayPageControl.ValueChanged event.
-(IBAction) pageChanged:(id)sender
{
int page = PageIndicator.currentPage;
// update the scroll view to the appropriate page
CGRect frame = ImagesScroller.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
[ImagesScroller scrollRectToVisible:frame animated:YES];
}
The application crashes in iOS7. I have a Solution for iOS 7:
Reason for Crash:
in iOS 7 [self.subViews objectAtIndex: i] returns UIView Instead of UIImageView and setImage is not the property of UIView and the app crashes. I solve my problem using this following code.
Check Whether the subview is UIView(for iOS7) or UIImageView(for iOS6 or earlier). And If it is UIView I am going to add UIImageView as subview on that view and voila its working and not crash..!!
-(void) updateDots
{
for (int i = 0; i < [self.subviews count]; i++)
{
UIImageView * dot = [self imageViewForSubview: [self.subviews objectAtIndex: i]];
if (i == self.currentPage) dot.image = activeImage;
else dot.image = inactiveImage;
}
}
- (UIImageView *) imageViewForSubview: (UIView *) view
{
UIImageView * dot = nil;
if ([view isKindOfClass: [UIView class]])
{
for (UIView* subview in view.subviews)
{
if ([subview isKindOfClass:[UIImageView class]])
{
dot = (UIImageView *)subview;
break;
}
}
if (dot == nil)
{
dot = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, view.frame.size.width, view.frame.size.height)];
[view addSubview:dot];
}
}
else
{
dot = (UIImageView *) view;
}
return dot;
}
Hope this solve ur issue too for iOS7. and If Anypone find the optimal solution for that please comment. :)
Happy coding
JWD answer is the way to go. However, if all you want is to just change the color, why not do this:
This technique will only work on iOS6.0 and higher!
Select your UIPageControl go to attribute inspector. Tada.
Or alternatively you can play around with these 2 properties:
pageIndicatorTintColor property
currentPageIndicatorTintColor property
This is so simple. I read the question again to make sure I am not wrong. You really just want to change the color don't you? Then yes.
You're still stuck with that lawsy dots. Use JWD technique for the awesome dot pictures.
just one line of code fir your demand. The example set to black color.
pageControl.pageIndicatorTintColor = [UIColor blackColor];
DDPageControl is an excellent replacement. Check it out!
You can also view the archived blog post here.
You can change the page indicator tint color and the current page indicator tint color with the following code:
pageControl.pageIndicatorTintColor = [UIColor orangeColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
if you just want to change color of dots or customize it you can make it as recommended by JWD, but in little bit another way:
#pragma mark - LifeCycle
- (void)setCurrentPage:(NSInteger)page
{
[super setCurrentPage:page];
[self updateDots];
}
#pragma mark - Private
- (void)updateDots
{
for (int i = 0; i < [self.subviews count]; i++) {
UIView* dot = [self.subviews objectAtIndex:i];
if (i == self.currentPage) {
dot.backgroundColor = UIColorFromHEX(0x72E7DB);
dot.layer.cornerRadius = dot.frame.size.height / 2;
} else {
dot.backgroundColor = UIColorFromHEX(0xFFFFFF);
dot.layer.cornerRadius = dot.frame.size.height / 2 - 1;
dot.layer.borderColor = UIColorFromHEX(0x72E7DB).CGColor;
dot.layer.borderWidth = 1;
}
}
}
As result you will get something like
Also macros:
#define UIColorFromHEX(hexValue) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0 green:((float)((hexValue & 0xFF00) >> 8))/255.0 blue:((float)(hexValue & 0xFF))/255.0 alpha:1.0]
The best and most siple way to do this is to add the following lines of code in the didFinishLaunchingWithOptions method in the AppDelegate.m
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor whiteColor];
You might wanna have a look on this solution in another stackoverflow question.
Here is a related answer for using a custom image (if you're flexible and can use an image rather than altering the colors directly).
Customize dot with image of UIPageControl at index 0 of UIPageControl

How would I add a dissolve transition to my code? (comic book)

How would I add a dissolve transition to my code?
I tried looking at Apple's code but to no avail. Any ideas?
#import "ApotheosisViewController.h"
#implementation ApotheosisViewController
#synthesize scrollView1;
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
const CGFloat kScrollObjHeight = 320.0;
const CGFloat kScrollObjWidth = 480.0;
const NSUInteger kNumImages = 40;
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (kScrollObjWidth);
}
}
// set the content size so it can be scrollable
[scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
}
- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
// 1. setup the scrollview for multiple images and add it to the view controller
//
// note: the following can be done in Interface Builder, but we show this in code for clarity
[scrollView1 setBackgroundColor:[UIColor blackColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleBlack;
scrollView1.clipsToBounds = NO; // default is NO, we want to restrict drawing within our scrollview
scrollView1.scrollEnabled = YES;
// pagingEnabled property default is NO, if set the scroller will stop or snap at each photo
// if you want free-flowing scroll, don't set this property.
scrollView1.pagingEnabled = YES;
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:#"image%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i; // tag our images for later use when we place them in serial fashion
[scrollView1 addSubview:imageView];
[imageView release];
}
[self layoutScrollImages]; // now place the photos in serial layout within the scrollview
}
- (void)dealloc
{
[scrollView1 release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// invoke super's implementation to do the Right Thing, but also release the input controller since we can do that
// In practice this is unlikely to be used in this application, and it would be of little benefit,
// but the principle is the important thing.
//
[super didReceiveMemoryWarning];
}
#end
I can't immediately tell what the code you posted has to do with a dissolve transition.
If you are trying to go from one view to another, then you could put this in your code:
In
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
for one viewController:
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
and when switching from one view to the other:
[self presentModalViewController:otherViewController animated:YES];