I am trying to overlay a play button on an image thumbnail
currentl the thumbnail is displayed using :
if(nil != self.analysis.image) {
self.imageView.image = self.analysis.image;
}
i tried to use the thumbnail as the background image , and the play button with transparency as the image, but it doesn't appear at all ...
if(nil != self.analysis.image) {
self.imageView.backgroundColor = [UIColor colorWithPatternImage:self.analysis.image];
self.imageView.image = [UIImage imageNamed:#"whiteBackground.png"];
}
What's the best way to compose them ?
My fault !
The coding is right...!! whiteBackground.png is transparent ....
I have to use the display button image ....
if(nil != self.analysis.image) {
self.imageView.backgroundColor = [UIColor colorWithPatternImage:self.analysis.image];
self.imageView.image = [UIImage imageNamed:#"displayButton.png"];
}
Related
I am trying to set scrollbar color in Amcharts, but none of the options specified on Amcharts site has worked.
I am using "#amcharts/amcharts4": "^4.2.2" in react app.
I have tried many options which are mentioned below. None of them are working.
chart.scrollbarX = new am4core.Scrollbar();
chart.scrollbarX.fill = "#017acd";
chart.scrollbarX.setFill(new am4core.color("#017acd"));
chart.scrollbarX.setStroke(new am4core.color("#017acd"));
chart.scrollbarX.stroke = "#017acd"; //this sets the border line color of
scrollbar.
Thanks for the help.
A scrollbar has a background, a thumb, a startGrip and an endGrip. Each of them can be styled individually by :
chart.scrollbarX.background.fill = am4core.color("#017acd");
chart.scrollbarX.thumb.background.fill = am4core.color("#017acd");
chart.scrollbarX.startGrip.background.fill = am4core.color("#017acd");
chart.scrollbarX.endGrip.background.fill = am4core.color("#017acd");
chart.scrollbarX.stroke = am4core.color("#017acd");
You can create different states for all the components to set different colors for hover or press (down).
chart.scrollbarX.thumb.background.states.getKey('hover').properties.fill = am4core.color("#017acd");
chart.scrollbarX.thumb.background.states.getKey('down').properties.fill = am4core.color("#017acd");
I created this code pen to show you a complete example.
If you want to style not a single scrollbar, but all the scrollbars in your app I would suggest creating a custom theme for that.
function am4themes_myTheme(target) {
if (target instanceof am4core.InterfaceColorSet) {
target.setFor("secondaryButton", am4core.color("#6DC0D5"));
target.setFor("secondaryButtonHover", am4core.color("#6DC0D5").lighten(-0.2));
target.setFor("secondaryButtonDown", am4core.color("#6DC0D5").lighten(-0.2));
target.setFor("secondaryButtonActive", am4core.color("#6DC0D5").lighten(-0.2));
target.setFor("secondaryButtonText", am4core.color("#FFFFFF"));
target.setFor("secondaryButtonStroke", am4core.color("#467B88"));
}
if (target instanceof am4core.Scrollbar) {
target.stroke = am4core.color("#017acd");
}
}
am4core.useTheme(am4themes_myTheme);
Here is a code pen showing a theme example.
I have a button that has an image from the gallery. The image is scaled to the display width and its height is set to half the display width. Now when I upload this image to the server, I send the imagePath which results in sending the orginal image of the gallery. How can I upload the icon of the button? (ie. width = display width and height = half of the display width)
getImageButton.addActionListener(f -> {
Display.getInstance().openGallery(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
if (evt == null) {
return;
}
imagePath = (String) evt.getSource();
Image i = Image.createImage(imagePath);
Image profileImgg = i.scaledWidth(Display.getInstance().getDisplayWidth());
getImageButton.setIcon(profileImgg);
getImageButton.setPreferredH((Display.getInstance().getDisplayWidth()/2)-50);
getImageButton.getParent().revalidate();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}, Display.GALLERY_IMAGE);
});
PS. I want to upload the icon of the button, not the image in the gallery.
The scaled method produces a new image instance it doesn't impact the file from which you loaded. Also this approach to scaling would distort the image aspect ratio. I would suggest a more sensible scaling strategy such as fill().
You have two options:
Convert the loaded image to a file object. The easy way is:
EncodedImage e = EncodedImage.createFromImage(img, true);
byte[] theDataOfTheImageFile = e.getImageData();
Transform the file directly using the ImageIO API
This is the code I'm using to create the Image that I'm inserting into a FlowDocument.
private static Image GetImage(string url)
{
if (url == null) throw new ArgumentNullException("url");
if (!(url.StartsWith("http://") || url.StartsWith("https://") || url.StartsWith("ftp://")))
return null;
var uri = new Uri(url, UriKind.Absolute);
var bmpImg = new BitmapImage(uri)
{
CacheOption = BitmapCacheOption.OnDemand,
};
if (bmpImg.CanFreeze) bmpImg.Freeze();
var img = new Image
{
Source = bmpImg,
Stretch = Stretch.Uniform,
Height = 120,
Width = 120,
};
return img;
}
When I create a document and insert an image from my server with
Designer.CaretPosition.Paragraph.Inlines.Add(image);
everything works fine - image displays as expected. Also, the main Google Logo image works fine, but the HackaDay Logo and others just display a blank image.
What could be the reason for this?
I think that some websites have hotlink protection. For example in my website I can link a photo in every page that it is in my domain and it works well, however if you try to link a photo in other domain, the photo doesn't load.
I have a view that pops up a UIAlertView if the name field for an item entry isn't populated when you attempt to save. I wanted to display my own custom alert view instead. I load it with a xib:
- (void)enterNameAlert {
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:#"AddNameAlertView" owner:self options:nil];
enterNameAlertView = [subviewArray objectAtIndex:0];
enterNameAlertView.frame = CGRectMake(232, 417, 303, 171);
enterNameAlertView.alpha = 0.0;
[self.view addSubview:enterNameAlertView];
[self.view bringSubviewToFront:enterNameAlertView];
//fade view in
[UIView animateWithDuration:.50f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void) {
enterNameAlertView.alpha = 1.0;
} completion:NULL];
[UIView commitAnimations];
}
However, you can still click on all the other elements on the view while the alert is displayed. Ideally, I'd like to make the alertview modal. As a hack, I just set xxxx.enabled = NO to all the other elements while the alertview is up, and switch them back to xxxx.enabled = YES when you press OK on the alert.
There has to be a better way to cancel all touches to self.view but not to self.enterNameAlertView.
If I do self.view.userInteractionEnabled = NO it cancels all touches to self.view as well as self.enterNameAlertView.
Any ideas?
I think the solution for your problem is that you have to introduce one more view in between your custom alert view and orignal view, once the alert comes you need to bring that view on your self.view and hide (or remove) it when your alert is dismissed, i have already done this and it work like charm for me. Hope this helps you too :)
Got it. I used a UIScrollView with interaction enabled. That stops touches from outside the custom alertview from being passed to the main view underneath.
- (void)enterNameAlert {
//pop a UIScrollView behind the alert so that the user can't touch the controls behind it
shadowScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
shadowScrollView.userInteractionEnabled = YES;
shadowScrollView.backgroundColor = [UIColor blackColor];
shadowScrollView.alpha = 0.0;
[self.view addSubview:shadowScrollView];
[self.view bringSubviewToFront:shadowScrollView];
//put the alertview in front of the disabled view to make it act like a modal view
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:#"AddNameAlertView" owner:self options:nil];
enterNameAlertView = [subviewArray objectAtIndex:0];
enterNameAlertView.frame = CGRectMake(232, 417, 303, 171);
enterNameAlertView.alpha = 0.0;
[self.view addSubview:enterNameAlertView];
[self.view bringSubviewToFront:enterNameAlertView];
//animate view in
[UIView animateWithDuration:.50f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void) {
shadowScrollView.alpha = .6;
enterNameAlertView.alpha = 1.0;
} completion:NULL];
[UIView commitAnimations];
}
I have a table with a big list of stuff that comes from a plist file and clicking each of them takes you to a new view, a xib.
I have 2 views inside that .xib, one for portrait and one for landscape
In my h file I have this:
IBOutlet UIView *portraitView;
IBOutlet UIView *landscapeView;
#property (nonatomic, retain) IBOutlet UIView *portraitView;
#property (nonatomic, retain) IBOutlet UIView *landscapeView;
In my m file this:
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:) name:#"UIDeviceOrientationDidChangeNotification" object:nil];
}
- (void) orientationChanged:(id)object
{
UIInterfaceOrientation interfaceOrientation = [[object object] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view = self.portraitView;
}
else
{
self.view = self.landscapeView;
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
self.view = portraitView;
} else if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
self.view = landscapeView;
}
return YES;
}
#end
Everything was working perfectly in iOS 5, showing landscape or portrait when needed.
Now with the iOS 6 update everything is a mess.
If I am in the table (portrait) view and click one item, it shows correct in portrait, if I rotate to landscape, the view shows the correct view as well, BUT being in landscape, if I go back to the table and select another item, it shows the portrait view instead of the landscape.
If I do the same but starting landscape, it shows portrait.
So, now the orientation is not working for anything.
The same happens to my other views using storyboard. They are portrait and always showed like that, now they rotate, shrink everything and leave my app as trash.
1- How can I fix the .xib orientation thing ?
2- How can I fix the storyboard orientation ? (they were static, now everything rotates (no code at all))
Thanks.
I think that I have a work around. It's ugly but it's working...
With iOS6 Apple suggest now to use 2 differences XIB file to switch between portrait & landscape view.
But if you want to use the previous method allowed in iOS 5.0 by "switching" between 2 UIView IBOutlet, you can try my ugly working solution. The idea is to rotate the view according to the orientation.
1) In you viewDidLoad, subscribe to orientation notification:
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:) name:#"UIDeviceOrientationDidChangeNotification" object:nil];
}
2) Add a method called by the notification:
-(void)orientationChanged:(NSNotification *)object{
NSLog(#"orientation change");
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation == UIInterfaceOrientationPortraitUpsideDown){
self.view = self.potraitView;
if(deviceOrientation ==UIInterfaceOrientationPortraitUpsideDown){
NSLog(#"Changed Orientation To PortraitUpsideDown");
[self portraitUpsideDownOrientation];
}else{
NSLog(#"Changed Orientation To Portrait");
[self portraitOrientation];
}
}else{
self.view = self.landscapeView;
if(deviceOrientation ==UIInterfaceOrientationLandscapeLeft){
NSLog(#"Changed Orientation To Landscape left");
[self landscapeLeftOrientation];
}else{
NSLog(#"Changed Orientation To Landscape right");
[self landscapeRightOrientation];
}
}
}
3) And finally, add rotation method for each orientation:
-(void)landscapeLeftOrientation{
// Rotates the view.
CGAffineTransform transform = CGAffineTransformMakeRotation(-(3.14159/2));
self.view.transform = transform;
// Repositions and resizes the view.
CGRect contentRect = CGRectMake(0, 0, 480, 320);
self.view.bounds = contentRect;
}
-(void)landscapeRightOrientation{
// Rotates the view.
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
self.view.transform = transform;
// Repositions and resizes the view.
CGRect contentRect = CGRectMake(0, 0, 480, 320);
self.view.bounds = contentRect;
}
-(void)portraitOrientation{
// Rotates the view.
CGAffineTransform transform = CGAffineTransformMakeRotation(0);
self.view.transform = transform;
// Repositions and resizes the view.
CGRect contentRect = CGRectMake(0, 0, 320, 480);
self.view.bounds = contentRect;
}
-(void)portraitUpsideDownOrientation{
// Rotates the view.
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159);
self.view.transform = transform;
// Repositions and resizes the view.
CGRect contentRect = CGRectMake(0, 0, 320, 480);
self.view.bounds = contentRect;
}
I suggest you to make a custom UIViewController class and inherit-ate from this class to save redundant code.
If you want to support both solution for ios5 and ios6 you can use a #endif macro to include the both code in your controllers.
Cheers
No need to send and receive notifications:
In your appdelegate.m the following method
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
is always called to check the window's orientation,
so a simple way around is to have the below described code in your appdelegate.m
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
if(self.window.rootViewController){
UIViewController *presentedViewController ;
if ([self.window.rootViewController isKindOfClass:([UINavigationController class])])
{
presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
}
else if ([self.window.rootViewController isKindOfClass:[UITabBarController class]]){
UITabBarController *controller = (UITabBarController*)self.window.rootViewController;
id selectedController = [controller presentedViewController];
if (!selectedController) {
selectedController = [controller selectedViewController];
}
if ([selectedController isKindOfClass:([UINavigationController class])])
{
presentedViewController = [[(UINavigationController *)selectedController viewControllers] lastObject];
}
else{
presentedViewController = selectedController;
}
}
else
{
presentedViewController = self.window.rootViewController;
}
if ([presentedViewController respondsToSelector:#selector(supportedInterfaceOrientations)]) {
orientations = [presentedViewController supportedInterfaceOrientations];
}
}
return orientations;
}
and implement
- (NSUInteger)supportedInterfaceOrientations
in the respective view controllers
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait; //Or anyother orientation of your choice
}
and to perform sudden action against orientation changes, implement the following method
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
This is very late for an answer, still I thought I should share this with you just in case,
I had the very same issue.
shouldAutorotateToInterfaceOrientation is deprecated iOS 6 onwards.
You need to parallel this method with the new supportedInterfaceOrientations and shouldAutorotate methods.
And it is very very important, you need to make sure that you set the root controller in your app delegate's applicationDidFinishLaunching method rather than simply adding the view controller's view ( or navigation Controller or tabBar Controller depending on what you are using ) as a subview to the window.