Adding both the title and image to an NSStatusItem [duplicate] - nsimageview

This question already has answers here:
NSStatusItem Button Title to the Right of the Image
(3 answers)
Closed 2 years ago.
I've been trying to figure out how to add both text and an image to an NSStatusItem. Here is a mockup of what i'm trying to do:
http://cl.ly/GjTO
I've tried using the statusIetm.view and adding a subview, I've tried setting both the title and image property for fun even though I know that doesn't work. 'm not trying to add a a custom window the the Status Item, but the temperature and condition icon found in the first image. If anyone has any idea, I'd love to hear them.
Thanks

statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
NSImage *statusImage = [NSImage imageNamed:#"icon.png"]; // must be 19x19 max
[statusItem setImage:statusImage];
NSImage *altStatusImage = [NSImage imageNamed:#"icon.png"];
[statusItem setAlternateImage:altStatusImage];
[statusItem setHighlightMode:YES];
[statusItem setAttributedTitle:attrString];
[statusItem setTitle:#"Loading..."];
[statusItem setMenu:statusMenu];

You can do this without a custom view like this:
button.imagePosition = NSControl.ImagePosition.imageLeft
Thanks to this answer.

Try creating a custom NSView and setting it with
[statusItem setView:myCustomView];

Related

Clear a UILabel text and reset it again in xcode?

I have a UILabel set its text.But when I check for some condition and try to
change the text of UILabel if condition not met then Im getting the other other text on already present text of UILabel i.e both texts are overlapping..First I want to clear the present text and reset same UILabel to other text ..How can i do it ?
Im doing this
label.text=#"Welcome";
if(check for some condition)
{
label.text=#"Sorry";
}
But both texts are overlapping on each other...Where Im going wrong?
If you want to clear label first
label.text = #"";
and then give some value to the label
label.text = #"Sorry";
I know it's silly but sometimes it works.
Thanks.
I was having the same problem with Swift 3. It was some intermittent that at times and a text exchange look like a label. I have decided as follows:
self.label.text = "00:00:00"
self.label.setNeedsLayout()
You can try this:
label.text = nil;
And after the condition, you reassign the text.

Attempts to tap a UIButton in a UITableViewCell using UI Automation fail with "could not be tapped"

I have an iPhone app that I'm testing using UI Automation.
I have a button in a UITableViewCell but when I try to tap on it using UI Automation I get the following error.
Script threw an uncaught JavaScript error: target.frontMostApp().mainWindow().scrollViews()[0].elements()[element_name].tableViews()[0].elements().firstWithPredicate(name contains[c] 'Brooklyn').elements()["detailsButton"] could not be tapped
I have enabled accessibility on the button in Interface Builder and assigned the accessibility label (and identifier) "detailsButton". I can retrieve the button element and have verified that it is valid. I just can't tap it for some reason.
The UIButton is a round rectangular button with user interaction enabled. Thanks for any feedback.
You can alloc the UIButton except using round rect button. And also you can set target action of button in your controller class where table view delegate methods are presents.
Try asserting first if the button exists, use tuneup_js for easy assertions.
Then assert if the button is enabled.
Have you tried:
target.frontMostApp().mainWindow().scrollViews()[0].elements()[element_name].tableViews()[0].**cells()**.firstWithPredicate("name contains[c] 'Brooklyn'").elements()["detailsButton"]?
Also post another picture which shows the UIATableCell expanded where the detailsButton exists.
You have to use ButtonType=Custom
I don't know why you are using UI Automation. But as much I know about adding UIButton in a tableviewcell-
1) just add UIButton in UITableViewCell.
2) set UIButton's tag value and add target to that button.
3) In the target button method, you can get the UIButton object and do your stuff over there..
Hope this helps you out.
but=[UIButton buttonWithType:UIButtonTypeCustom];
You must use a custom button type.
I have met the same problem. After I added the delay it works.
UIATarget.localTarget().delay(1);
You can dispatch a tap event over the entire window:
function tap_from_window(elem) {
var mainWindow = target.frontMostApp().mainWindow();
var elemRect = elem.rect();
var windowRect = mainWindow.rect();
var xPos = (20 + elemRect.origin.x) / windowRect.size.width;
var yPos = (50 + elemRect.origin.y) / windowRect.size.height;
mainWindow.tapWithOptions({tapOffset:{x:xPos, y:yPos}});
}
var target = UIATarget.localTarget();
var window = target.frontMostApp().mainWindow();
var tableView = window.scrollViews()[0].elements()[element_name].tableViews()[0];
tap_from_window(tableView.elements().firstWithPredicate(name contains[c] 'Brooklyn'))
Like many things related to iOS, I have no idea why the element cannot be tapped directly. I adapted the above function from the code in this post: scrollToVisible error while testing on a device, UIAutomation

MonoTouch : Can I use a UILabel to show a phone number?

I need to show a phone number in a view and that when clicked a call is initiated. Currently I'm using an UILabel and I have no idea how to do it.
Is this the correct control? If no which one would be?
If it's the correct one, how can I do it?
An UILabel could be used (kind of showing a link) but an UIButton might be more appropriate.
You can find the code to initiate the code from this question (and answer).
Using a UIButton and the code from above would give you:
var btn = UIButton.FromType(UIButtonType.RoundedRect);
btn.Frame = new RectangleF (10,10,100,200);
btn.SetTitle ("call me", UIControlState.Normal);
btn.TouchUpInside += delegate {
UIApplication.SharedApplication.OpenUrl (NSUrl.FromString ("tel://411"));
};

Multiple red/destructive buttons UIActionSheet

Is there any way to have more than 1 red "destructive button" in an iPhone app's UIActionSheet?
I need to have different clear options, in the same action sheet, one where it deletes everything and one where it deletes less, so both need to be red.
I just created a simple customizable replacement for UIActionSheet for iPhone to use in a similar case. It does not use the standard appearance, but this can be changed. Probably it is of any use to you.
https://github.com/4marcus/WMActionSheet
The poster of this question seemed to manage what you want...if i understand you correctly.
Is using subviews in Alert undocumented
EDIT:
I swear I searched for UIActionSheet the first time. Really.
http://www.nearinfinity.com/blogs/andrew_homeyer/display_a_custom_uiview_like_a.html
There's no supported way of doing this on the standard UIActionSheet. You could build your own "action sheet" replacement using gradient buttons like the ones here:
http://iphonedevelopment.blogspot.com/2010/05/gradient-buttons-yet-again.html
I would expect someone to have created a more customizable lookalike action sheet replacement, but I don't know of one off the top of my head.
I tried this before I saw griotspeak updated answer:
SEL getTitle = NSSelectorFromString(#"title");
SEL getBackground = NSSelectorFromString(#"background");
SEL setBackground = NSSelectorFromString(#"setBackgroundImage:");
SEL setTitleColor = NSSelectorFromString(#"setTitleColor:");
UIImage *redImage;
UIColor *titleColor;
UIColor *shadowColor;
for (NSObject *object in [action subviews]) {
if ([[NSString stringWithFormat:#"%#", [object class]] isEqualToString:#"UIThreePartButton"]) {
if ([[object performSelector:getTitle] isEqualToString:#"Clear all"]) {
redImage = [object performSelector:getBackground];
titleColor = [object performSelector:#selector(titleColor)];
shadowColor = [object performSelector:#selector(shadowColorForState:) withObject:0];
shadowOffset = [object performSelector:#selector(shadowOffset)];
}
if ([[object performSelector:getTitle] isEqualToString:#"Clear all except this month"]) {
[object performSelector:setBackground withObject:redImage];
[object performSelector:setTitleColor withObject:titleColor];
[object performSelector:#selector(setShadowColor:) withObject:shadowColor];
//[object performSelector:#selector(setShadowOffset:) withObject:CGSizeMake(-2.5,0)];
}
}
}
(I use NSSelectorFromString rather than a #selector() because it means it's not really using undocumented things, kind of, if you get what I mean)
It's not entirely documented but I don't think I've used undocumented methods.
Basically what it does is take the red background from the destructive background and apply it to the other button named "Cancel".
So that should Apple change the color of the destructive button, so will the non-destructive-destructive change as well without needing an update. Although it doesn't use particularly Apple-safe methods.
I'm having a little bit of trouble with the commented-out line above, if you can help please answer here: performSelector:withObject:, but not with an object

iPhone UIActionSheet with multiple red, destructive buttons [duplicate]

Is there any way to have more than 1 red "destructive button" in an iPhone app's UIActionSheet?
I need to have different clear options, in the same action sheet, one where it deletes everything and one where it deletes less, so both need to be red.
I just created a simple customizable replacement for UIActionSheet for iPhone to use in a similar case. It does not use the standard appearance, but this can be changed. Probably it is of any use to you.
https://github.com/4marcus/WMActionSheet
The poster of this question seemed to manage what you want...if i understand you correctly.
Is using subviews in Alert undocumented
EDIT:
I swear I searched for UIActionSheet the first time. Really.
http://www.nearinfinity.com/blogs/andrew_homeyer/display_a_custom_uiview_like_a.html
There's no supported way of doing this on the standard UIActionSheet. You could build your own "action sheet" replacement using gradient buttons like the ones here:
http://iphonedevelopment.blogspot.com/2010/05/gradient-buttons-yet-again.html
I would expect someone to have created a more customizable lookalike action sheet replacement, but I don't know of one off the top of my head.
I tried this before I saw griotspeak updated answer:
SEL getTitle = NSSelectorFromString(#"title");
SEL getBackground = NSSelectorFromString(#"background");
SEL setBackground = NSSelectorFromString(#"setBackgroundImage:");
SEL setTitleColor = NSSelectorFromString(#"setTitleColor:");
UIImage *redImage;
UIColor *titleColor;
UIColor *shadowColor;
for (NSObject *object in [action subviews]) {
if ([[NSString stringWithFormat:#"%#", [object class]] isEqualToString:#"UIThreePartButton"]) {
if ([[object performSelector:getTitle] isEqualToString:#"Clear all"]) {
redImage = [object performSelector:getBackground];
titleColor = [object performSelector:#selector(titleColor)];
shadowColor = [object performSelector:#selector(shadowColorForState:) withObject:0];
shadowOffset = [object performSelector:#selector(shadowOffset)];
}
if ([[object performSelector:getTitle] isEqualToString:#"Clear all except this month"]) {
[object performSelector:setBackground withObject:redImage];
[object performSelector:setTitleColor withObject:titleColor];
[object performSelector:#selector(setShadowColor:) withObject:shadowColor];
//[object performSelector:#selector(setShadowOffset:) withObject:CGSizeMake(-2.5,0)];
}
}
}
(I use NSSelectorFromString rather than a #selector() because it means it's not really using undocumented things, kind of, if you get what I mean)
It's not entirely documented but I don't think I've used undocumented methods.
Basically what it does is take the red background from the destructive background and apply it to the other button named "Cancel".
So that should Apple change the color of the destructive button, so will the non-destructive-destructive change as well without needing an update. Although it doesn't use particularly Apple-safe methods.
I'm having a little bit of trouble with the commented-out line above, if you can help please answer here: performSelector:withObject:, but not with an object