I want to place an animated background on my app. I have looked into the UIMotionEffect class and yes that does seem beneficial. However, what I am really looking for is something like the dynamic wallpapers provided in iOS settings. The way those colored circles move around is exactly what I am looking for.
I've tried this with no luck:
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"circle"]];
[UIView animateWithDuration:5.0 animations:^{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"circle"]];
}];
My only problem is I have no idea where to start. I looked into OpenGL. I assume it could be done that way, but it seems like a possible rabbit trail that I might not need to take. I also found some videos on YouTube but they involve Adobe Flash, which I do not have. Any suggestions on where to venture for this?
If it's a simple GIF you don't need to get fancy. Just separate the images (many tools to do that) and use the following code (might be some typos):
NSArray *array = [NSArray arrayWithObjects:
[UIImage imageNamed:#"image1.png"],
[UIImage imageNamed:#"image2.png"],
........,
nil];
UIImage *image = [UIImage animatedImageWithImages:array duration:6.0f];
[image startAnimating];
Related
I am currently learning iOS development and I want to develop an iOS app where there is an animated image at the beginning top of the View Controller and a lot of text just after it. Please have a look at the picture below:
I have thought about the codes for both the image animation at the top and the large amount of text just after it. I was wondering whether someone could please review them and tell me whether they are fine or not.
The codes for both the image animation and the large amount of text will be placed inside the viewDidLoad method of the implementation file of the controller like this:
- (void)viewDidLoad
{
[super viewDidLoad];
// codes for image animation
// codes for large amount of text to be displayed
}
IMAGE ANIMATION CODES
For the image animation, I am going to use 5 png pictures: A.png, B.png, C.png, D.png and E.png. The slide show will start from A, then move on to B, then to C, to D and finally to E. All the 5 pictures are added to my project in Xcode. Below are the codes:
NSArray *imagelist = [[NSArray alloc] initWithObjects: [UIImage imageNamed:#"A.png"], [UIImage imageNamed:#"B.png"], [UIImage imageNamed:#"C.png"], [UIImage imageNamed:#"D.png"], [UIImage imageNamed:#"E.png"],nil];
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame: CGRectMake(5,5,90,180)];
animationImageView.animationImages = imagelist;
animationimageView.animationDuration = 10;
[self.view addSubView:animationimageView];
[animationImageView startAnimating];
LARGE AMOUNT OF TEXT CODES
For the text, I have not added all the necessary text....because there is a lot more. That is why I need the text object to be scrollable. Below are the codes:
UITextView *largeText = [[UITextView alloc] initWitthFrame: CGRectMake(5,100,90,180)];
largeText.text = #"In organizations, we must work with and for others. To be able to mutually achieve our goals, we must be able to relate to others effectively. These leadership tips will help you do just that:
1)Catch people doing things right and then let them know that they are doing things right
2)Use feedback to stay informed about what other people are doing in your area of responsibility and authority
3)Have regular, focused meetings regarding the projects that you are responsible for
4)Provide adequate instructions. Time is lost if things are not done correctly
5)Train others to do jobs. You cannot do them all, nor can others do them if they have not been trained
6)Expect others to succeed. It becomes a self-fulfilling prophecy when you believe others are loyal, dedicated and doing a good job";
largeText.font = [UIFont fontWithName:#"TimesNewRomanPSMT" size:18];
largeText.editable = NO;
largeText.scrollEnabled = YES;
[self.view addSubView:largeText];
Please review the codes and can someone tell me whether the codes are fine or not.
Thanks for reading.
NSArray *imagelist = [[NSArray alloc] initWithObjects: [UIImage imageNamed:#"A.png"], [UIImage imageNamed:#"B.png"], [UIImage imageNamed:#"C.png"], [UIImage imageNamed:#"D.png"], [UIImage imageNamed:#"E.png"],nil];
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame: CGRectMake(5,5,90,180)];
[self.view addSubView:animationimageView];
NSTimeInterval delay=0.0;
for (NSInteger i=0; i<[imagelist count]; i++) {
delay+=3.0;
[UIView animateWithDuration:0.5 delay:delay options:UIViewAnimationOptionCurveLinear animations:^{
animationImageView.image=[imagelist objectAtIndex:i];
}completion:nil];
}
I'm looking for advice about how best to implement a Karaoke text effect to an IOS app. I'm new to IOS so am not familiar with all the various animation apis and libraries and am hoping that I can save some time if I am pointed in the right direction of what libraries to study.
In Javascript I would have used an array with the various words and timings of the audio track, and setTimeout to write the next element in the array to a div on the page. I did consider using this approach in a UIWebView but after some quick tests with UIWebview I wasn't really happy with how smooth it looked.
I did come across one very simple animation tutorial that loops through an array of images but it has a uniform animation duration which in my use case would not work, as the length of time the words needs to display on the screen will vary according to the audio. Here is the sample code that I was looking at.
NSArray *imageNames = #[#"win_1.png", #"win_2.png", #"win_3.png", #"win_4.png",
#"win_5.png", #"win_6.png", #"win_7.png", #"win_8.png",
#"win_9.png", #"win_10.png", #"win_11.png", #"win_12.png",
#"win_13.png", #"win_14.png", #"win_15.png", #"win_16.png"];
NSMutableArray *images = [[NSMutableArray alloc]init];
for (int i= 0; i < imageNames.count; i++) {
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}
UIImageView *animationImageView = [[UIImageView alloc] initWithFrame: CGRectMake(60,95, 86, 193)];
animationImageView.animationImages = images;
animationImageView.animationDuration = 0.5;
[self.view addSubview:animationImageView];
[animationImageView startAnimating];
UIImageView *slowAnimationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(160, 95, 86, 193)];
slowAnimationImageView.animationImages = images;
slowAnimationImageView.animationDuration = 5;
[self.view addSubview:slowAnimationImageView];
[slowAnimationImageView startAnimating];
And I found that tutorial here: http://www.appcoda.com/ios-programming-animation-uiimageview/
thanks in advance for any suggestions of which approach is best to take.
So, I have already implemented what you describe and I can tell you that CoreText is the API you need to use. Only via CoreText rendering will you be able to render specific word portions in different colors and apply the color changes at specific times. But, the bad news is that this API is not really easy to use. You can find working example code in the files MutableAttrString.m and AVOfflineComposition.m at the following github project link github. The minimum code you would need is in the MutableAttrString.m file, it shows how to use CoreText to properly implement the logic you describe. You could try to roll your own solution with animated bitmaps, but the CoreText approach just renders text so it is way better for many reasons.
I'm making an app designed for iOS 6 and 7, and I want to allow users to choose which style they want: iOS 6 or iOS 7. Or at least just make it have the iOS 6 style completely. The app needs to be acceptable on the App Store.
I'm considering trying to find iOS 6 button images to use, but since I'm new to iOS GUI programming, I'm wondering if there is a cleaner way to do this that I don't know about. Is there a framework I could simply add so that I can use something like "[[UIButton6 alloc] init]" etc to make buttons with the older style? Or could I easily do this myself with rendering settings?
Any other approaches would also be helpful. Also, answers saying that this isn't possible at all are fine, but please no answers telling me that I should just use the iOS 7 GUI. I'm asking "how/can" I do this, not "should" I do this.
What I do is to add the drawing of an oval shape with a gradient background, myself. For example, here's code from one of my apps:
CAGradientLayer* grad = [CAGradientLayer new];
grad.frame = CGRectMake(0,0,15,15);
grad.colors = #[(id)[UIColor colorWithRed:1 green:1 blue:0 alpha:0.8].CGColor,
(id)[UIColor colorWithRed:.7 green:.7 blue:.3 alpha:0.8].CGColor];
UIGraphicsBeginImageContextWithOptions(CGSizeMake(15,15), NO, 0);
UIBezierPath* p = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0,0,15,15) cornerRadius:8];
[p addClip];
[grad renderInContext:UIGraphicsGetCurrentContext()];
[[UIColor blackColor] setStroke];
p.lineWidth = 2;
[p stroke];
UIImage* im = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
im = [im resizableImageWithCapInsets:UIEdgeInsetsMake(7,7,7,7) resizingMode:UIImageResizingModeStretch];
Now use im as the background image of the button.
That code is just a "serving suggestion"; try it and then change the gradient colors or get rid of the gradient or whatever you feel like doing.
RED FLAG:
If you want to be accepted on the App Store, then intentionally targeting the iOS 6 look and feel is a serious danger.
As of February 1st, Apple is expecting all applications to be "optimized for iOS 7", which doesn't immediately exclude what you're discussing, but I wouldn't risk it personally.
Matt's answer is good, but I found a way to do this without rendering an image. Might be faster, and the code is more compact. I also like it a lot better when the gradient has 3 stops:
CAGradientLayer* grad = [CAGradientLayer new];
grad.frame = CGRectMake(0,0,button.frame.size.width,button.frame.size.height);
grad.colors = #[(id)[UIColor colorWithWhite:1 alpha:1].CGColor,(id)[UIColor colorWithWhite:.95 alpha:1].CGColor,(id)[UIColor colorWithWhite:1 alpha:1].CGColor];
grad.locations = #[#(0), #(.5), #(1)];
grad.cornerRadius = 10;
grad.borderColor = [UIColor blackColor].CGColor;
grad.borderWidth = .2;
[button.layer insertSublayer: grad atIndex:0]; //button is the UIButton you want to modify
Of course, edit the gradients, border, etc as needed. Here's what it looks like:
P.S. In case anyone "ninja'd" me, I originally said in this post that matt's answer doesn't allow you to set the gradient stops, but I was wrong.
I have a MKMapView and I would like to take a screenshot of it and share it to a social network, for example to Facebook. I've found a nice way to make the screenshot, using MKMapSnapshotter (which is available starting with iOS 7), but my question is: Am I able to share a screenshot of MKMapView? Does Apple allow this?
I found this similar question, but there is not given any clear answer.
Try Google Maps SDK for iOS:
Documentation
And to make the screenshot use the following code:
CGRect rect = [captureView bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[captureView.layer renderInContext:context];
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Yes of course, why would apple object you?
You can surely share the image. As you mentioned you have the image you just need to use default sharing sheet. here's the code:
NSArray *activityItems = [NSArray arrayWithObjects:yourImage, nil];
UIActivityViewController *aActivityView = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
aActivityView.modalInPopover = UIModalTransitionStyleCoverVertical;
[self presentViewController:aActivityView animated:YES completion:^{
}];
This will present an UIActivityViewController's view which will have share option in it.
Hope this helps.
My gut feeling would be; why wouldn't Apple allow this?
If you have already managed to grab a UIImage representation of your MKMapView using the Apple provided MKMapSnapshotter, I would hazard a guess that Apple have given you the tools you need to do whatever you want with the image so there would be no restrictions as to what you do with it.
I have an UISwitch in my iOS 6 app, that's on and off image is customised.
self.testSwitch.onImage = [UIImage imageNamed:#"on"];
self.testSwitch.offImage = [UIImage imageNamed:#"off"];
I use 77 points wide and 22 points tall image for this purpose (154x44 in retina), as it is stated in the documentation. But my image does not fit to my uiswitch, it seems ugly, the default style hides my one, like on the attached image.
What should I set to make it work in a proper way?
Here is code from my book. This is not exactly what you want to do, but it shows the technique and will get you started! Notice that I'm using 79 by 27 (not sure where you got your numbers from):
UIGraphicsBeginImageContextWithOptions(CGSizeMake(79,27), NO, 0);
[[UIColor blackColor] setFill];
UIBezierPath* p = [UIBezierPath bezierPathWithRect:CGRectMake(0,0,79,27)];
[p fill];
NSMutableParagraphStyle* para = [NSMutableParagraphStyle new];
para.alignment = NSTextAlignmentCenter;
NSAttributedString* att =
[[NSAttributedString alloc] initWithString:#"YES" attributes:
#{
NSFontAttributeName:[UIFont fontWithName:#"GillSans-Bold" size:16],
NSForegroundColorAttributeName:[UIColor whiteColor],
NSParagraphStyleAttributeName:para
}];
[att drawInRect:CGRectMake(0,5,79,22)];
UIImage* im = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.sw2.onImage = im;
Looks like this:
Apple doesn't have an Appearance API for UISwitch. You can set a tint color property (onTintColor). But that's not what you want, I guess. The problem about customizing UISwitch is that there's the opportunity that Apple will reject your app.
But there are some APIs for a custom switch such as RCSwitch(https://github.com/robertchin/rcswitch) or TTSwitch. A good tutorial and example of how to use RCSwitch can be found here: http://www.raywenderlich.com/23424/photoshop-for-developers-creating-a-custom-uiswitch.