I am working on an iOS project that would like to showa and hide UIImages in an array for milliseconds in objective-c language. I don't know how?
Perhaps you’re looking for the animationImages property in the UIImageView class. You can set an array of UIImages, a duration and a repeat count.
https://developer.apple.com/documentation/uikit/uiimageview/1621068-animationimages
Related
I recently discovered that in > iOS5 UINavigationBar does not get its drawRect called. I want to figure out how to draw with Core Graphics in a category.
The end goal I am trying to achieve is eliminating images from my app and have everything drawn at runtime. I am also trying to make this library automatic, so that users don't have to think about using my custom classes.
Is there a way to replace a class with one of your own at runtime? like: replaceClass([UINavigationBar class], [MyCustomBar class]);
Thanks in advance.
Is there a way to replace a class with one of your own at runtime?
In Objective-C this is know as class posing.
Class posing is based on the use of NSObject's poseClass method, which is now deprecated (on 64 bit platforms, including the iPhone).
Alternative approaches have been investigated; you can read about one here, but they do not seem quite to fit the bill.
I found the solution, Instead of messing with draw rect, I just made some methods that draw to a UIImage then set the image as the background view for the elements i am customizing. It makes my custom UI magic again.
Is there a way, using the Interface Builder, in XCode to display a random image? So let's say I have three images and want a random one to display each time my app is loaded. I'm new to XCode, so I'm looking for the simplest way to do it and IB seems to be the route to take. Thanks!
After thinking about this for a few seconds, I realized the answer is of course you can, but it is such a pain, that I doubt that you would want to. I came up with a approach as an example of how to use IB in such a way.
First, subclass UIImageView, I will call it MyRandomImageView. The only member of MyRandomImageView is #property (retain, nonatomic) NSString *randomImageJSON.
Next, add a UIImageView to your view. In the Identity Inspector, change the Custom Class from UIImageView to MyRandomImageView. Then in the Identity Inspector, under User Defined Runtime Attributes, set randomImageJSON to something like [ "image1.png", "image2.png", "image3.png" ].
The final part is where you have all the trouble. Create -[MyRandomImageView setRandomImageJSON]. It needs to set the _randomImageJSON iVar, use NSJSONSerialization to create the array of strings, randomly pick one of the strings, then set self.image = [UIImage imageNamed:randomImage]
This should do exactly and you wish, a random image from the Interface Builder. Hope that helps.
You have to do this programmatically. Haven't tested the code below, but I'm pretty sure it works.
int imageNumber = arc4random() % 3;
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:#"%i", imageNumber]]];
You should first declare it in the implementation and link it to your UIImageView in the Interface Builder.
I have a project base on twitter's twui framework.I'm trying to made a string clickable just like
[s addAttribute:NSLinkAttributeName value:#"http://apple.com/" range:attrRange];
in NSMutableAttributedString, or performing a selector when clicked.
TUITextRender can draw a NSAttributedString, but "NSLinkAttributeName" doesn't work.
I can't find any method or delegate to solve this in TUITextView too.
How can I done this with twui?
After read source code, I figured it out.
Store ranges in a array of ABActiveRange (Which contains in twui) subclass.
Implement TUITextRendererDelegate in your UIViewController.
In the activeRangesForTextRenderer: delegate method, return the array you made in step 1.
Enjoy ~
I'm trying to create a conditional that asks about the button's image.
Here's what I have:
if (buttonName.image == [UIImage imageNamed:#"ButtonImage.png"])
This code works fine if the object buttonName is a UIImageView, but as a UIButton, I get the error 'request for member 'image' in something not a structure or union'.
How can I create this conditional?
== checks for pointer equality, so generally I would recommend using isEqual: which works on NSObjects, but this may not work for a UIImage (though UIImage does inherit from NSObject so give it a go).
If that fails, you might try using the CGImage property of a UIImage. This is the underlying Quartz image data, so you may be able to detect if the two images have the same CGImage (again, using == will not work, but isEqual may).
One way around this is to use the tag property of the UIButton, but this takes only ints, so you'll have to do some re-writing.
using IB, i found that you could use NSArray not in a programatic way. I was thinking, great, i can make sets of uiviews into an NSArray and then get a proper outlet in xcode and retreiving all my uiviews from the NSArray.
The fact is when i put a NSArray into the nib file, i can't do nothing into it's property list. So the fact is i don't use the NSArray the correct way it should be. So is there anyone who could explain me how can i use my nsArray the way i want to? This will explain me why using non-display class into the nib file, and the purpose of it.
Thanks.
You can instantiate an NSArray instance in a nib file using the "Object" item in the IB library...but you probably don't want to.