Today Widget indented / doesn't use all space - xcode

Building a Today Widget in iOS, and my view doesn't take up the full width of the screen:
See in the above screenshot that anything that goes beyond that point of the screen gets cut off.
I have set this up using the standard storyboard provided with the Today Widget extension:
This is confusing to me because I see plenty of other app's Today extensions use the full width of the screen.

you need to implement widgetMarginInsetsForProposedMarginInsets: like this
func widgetMarginInsetsForProposedMarginInsets(defaultMarginInsets: UIEdgeInsets) -> UIEdgeInsets {
return UIEdgeInsetsZero
}
check Apple Doc - Design the UI

Related

How to connect Help menu in SwiftUI MacOS DocumentGroup app to application logic?

SwiftUI DocumentGroup apps provide standard menu items including Help.
By default, when we run the app, and click Help / "MyApp help" we see "Help isn't available for MyApp".
Here's the main app:
import SwiftUI
#main
struct MyApp: App {
var body: some Scene {
DocumentGroup(newDocument: { MyDocument() }) { configuration in
ContentView()
}
.commands {
// use CommandGroup to modify built-in menu behavior
// the following would work to replace the entire help menu
// but I just want to access the logic for the
// second of two Help sub-menus
CommandGroup(replacing: .help) {
// How do I access the logic for Help / MyApp Help?
}
}
}
}
I've reviewed the standard documentation, tutorials, and UI guidelines, but don't see much on how to integrate behaviors and adjustments to the standard menu options. Any assistance would be much appreciated.
This question from a year ago is similar, but unanswered.
When working with SwiftUI menus, the key objects are CommandGroup and CommandGroupPlacement.
There's a great example in "Swift with Majid: Commands in SwiftUI dated 24 Nov 2020". Scroll nearly to the end to see how to use CommandGroupPlacement (e.g., .help or .newItem) to identify locations on the standard menu.
The example shows how to indicate whether our content should appear before, or after, or whether it should be replacing the CommandGroupPlacement menu location specified.
I generally prefer written documentation over videos, but the video and example code recommended in the question comments is quite useful - thank you user1046037.

Tab Bar Ignoring UITraitCollection requests - 6 Tabs Desired

I'm using the following code to trick my application into believing it's an iPad and displaying 6 tabs on the tab bar.
-(UITraitCollection *)traitCollection
{
UITraitCollection
*realTraits = [super traitCollection],
*lieTrait = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
return [UITraitCollection traitCollectionWithTraitsFromCollections:#[realTraits, lieTrait]];
}
This is all well and good, apart from when returning from a SFSafariViewController which I've rotated a couple of times. The issue I'm having is that the tab bar defaults back and shows four tabs along with the more page. What's my issue? It's important to note that just opening the SFSafariViewController and then going back DOESN'T trigger the Tab Bar to default - so I'm presuming it has something to do with the rotation putting a new view on top (a view which is ignoring the UITraitCollection call).
I've subclassed the SFSafariViewController and UITabBarController, while trying to call the method above when ever possible to stop the Tab Bar defaulting - however I'm having no success.
NOTE: I am getting a, '[App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction' error when rotating - if that is of any help.
Thank You.
I ended up solving this by implementing the snippet below into my suclassed UINavigationController.
- (UITraitCollection *)overrideTraitCollectionForChildViewController:(UIViewController *)childViewController
{
return [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
}
Hope that helps someone else with the problem!

App did not run at iPhone resolution when reviewed on iPad running iOS 10.2.3

This is my first iOS app, designed explicitly for the iPhone, not iPad, but apparently Apple won't put it on their store unless it will run on a iPad as well. I'm at a total loss as how to "fix" this. I've searched everywhere for suggestions and nothing I've tried works (including here on StackOverflow). I can run the app in the iPad simulator and get the same results as Apple does, but can't seem to find a fix. This is proving extremely frustrating, especially when one considers that this app won't run on a iPad because it needs access to a cellular network.
I'm using the latest Xamarin for Visual Studios and I'm using Visual Studios 2013. There is no mention of the iPad in Info.plist or anywhere else for that matter
Anyone have any suggestions?
R/
Prescott ....
You are receiving this from Apple because you might have indicated your app is an Universal App.
To indicate your application will only run on iPhones you need to set this in the info.Plist file if using Xamarin Studio. When using Visual Studio this is in the project properties. The option is called "Devices" make sure you select iPhone/iPod from the dropdown list.
Device selection in VS2017
I know you said you are using 2013 but this might give you an idea.
All,
Apple requires that apps run on all iOS platforms. Accordingly I had to add constraints to my storyboard to adjust the location of subviews on each screen. Because adding each constraint is tedious, I used Cirrious Fluent Layout which worked very well for me. Below is the code I used on my screen that included a imageview. This was the most complicated screen to "fix" because (apparently) the imagevies somehow changed all the screen sizes, being an iOS developer novice, I had no idea why this worked, only that it did.
First I needed to add the reference:
using Cirrious.FluentLayouts.Touch;
Code:
//This line is required to turn off all autosizing/positioning
View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
// Get the screen dimensions and the middle of the screen
// for button positioning
var barheight = this.NavigationController.NavigationBar.Bounds.Height;
// Height of the navigation bar
var height = UIScreen.MainScreen.Bounds.Height;
var width = UIScreen.MainScreen.Bounds.Width;
int middle = (int) UIScreen.MainScreen.Bounds.Width / 2;
// We cast to int to truncate float,
// int will convert implictly to float when used (Visual Studio).
var heightavailabletoimageviw = height -74 - 47 - 26 - 60;
// 74 is the height of the banner, 47 is the height of the buttons and
// 26 is the height of the title label plus a 5px gap The rest of the
// screen is available for use by the image view,
// set heightavailabletoimageviw to this value
// Had to subtract 60 because the image view still overlapped
// the buttons, no idea why. Anyone?
// Had to add a constraint to the imageview because if I didn't
// it automatically scaled to the size of the image, not good.
ThePhoto.AddConstraints(
ThePhoto.Width().EqualTo(UIScreen.MainScreen.Bounds.Width),
ThePhoto.Height().EqualTo(heightavailabletoimageviw)
);
// Had to fix the size of the imagebutton otherwise the button size
// scaled to the size of the image
btnPhoto.AddConstraints(
btnPhoto.Width().EqualTo(62f),
btnPhoto.Height().EqualTo(47f)
);
// Now we add the constraints to the viewcontroller to finish up.
View.AddConstraints(
// Can't cover the navigation bar (unless it isn't there, mine is),
// this value sets all other relative positions
Banner.AtTopOf(View, barheight),
Banner.AtRightOf(View, 0),
Banner.AtLeftOf(View, 0),
lblTitle.Below(Banner, 0),
lblTitle.WithSameWidth(Banner),
ThePhoto.Below(lblTitle, 5),
ThePhoto.WithSameWidth(lblTitle),
// I have no idea why, but I had to use negative
// values for the buttons to appear on the screen,
// otherwise they were off screen.
// If anyone could explain this, I would appreciate it.
btnUpload.AtBottomOf(View),
btnUpload.ToLeftOf(View,-60),
// Same here, had to use negative values for button to
// position correctly on the screen
btnPhoto.AtBottomOf(View),
btnPhoto.ToLeftOf(View,-(middle + 31)),
// Again, same thing.
btnMainMenu.AtBottomOf(View),
btnMainMenu.ToRightOf(View,-80)
);
This is how I solved my problem, I re-submitted the app and it now appears on the app store at: https://itunes.apple.com/us/app/oml-photo-manager/id1212622377?mt=8.
Hope this helps someone ....
R/
Prescott ...

Xcode IB Stupid Warning

Once again Xcode IB frustrates developers with unnecessary warnings: I cannot seem to get remove this warning from my Xcode project.
When double clicking the warning it brings up my MainMenu.xib file but gives no reference to what is causing the issue. Any ideas?
EDIT:
I've stripped down much of my .xib for public viewing but still have the error with very few objects. You can find the file here: https://www.dropbox.com/s/r2piuojr86dhlt9/MainMenu.xib?dl=0
This is a warning shown starting from Xcode 7 when UI elements like a label or table view column header use a font style or variation that is on available on older OS (and of course your project is still targeting them).
In my project a table view column header was using system font with "medium" font style variation instead of regular on a project targeting OS X 10.9+.
The weird thing is I had to restart Xcode as Interface Builder refused to change the style of the control. Possibly a small glitch of this early 7.0.1 Xcode version.
Anyway, either setting every control style to Regular or changing your project target to 10.11 should fix the warning.
Once again Xcode IB frustrates developers with unnecessary warnings.
Felt the same way about it too, until I saw how my typography differs in 10.10 compared to 10.11. One thing is true – the message is rubbish without pointing to a problematic storyboard item, see P.S section of the post for a semi-workaround.
Current answer almost gets it, but problem is not with font styles being unavailable in older targets, it's with Xcode not handling them properly, see full blog post for details.
If you want to keep your styles, use custom textfield with custom inspectable property. Open up identity inspector and set custom class to TextField, preferred font weight attribute will show up in attribute inspector, set the required value, build and enjoy the result.
import AppKit
#IBDesignable public class TextField: NSTextField
{
#IBInspectable public var preferredFontWeight: Int = 0
override public func awakeFromNib() {
if #available(OSX 10.11, *) {
return
}
guard
let weight: Int = self.preferredFontWeight where weight > 0,
let font: NSFont = self.font,
let name: String = font.familyName,
let manager: NSFontManager = NSFontManager.sharedFontManager() else {
return
}
// Full details here – https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSFontManager_Class/#//apple_ref/occ/instm/NSFontManager/convertWeight:ofFont:
//
// 1 – ultralight
// 2 – thin
// 3 – light, extralight
// 4 – book
// 5 – regular, display
// 6 – medium
// 7 – demi, demibold
// 8 – semi, semibold
// 9 – bold
// 10 – extra, extrabold
// 11 – heavy
// 12 – black
// 13 – ultrablack
// 14 – extrablack
if let font: NSFont = manager.fontWithFamily(name, traits: manager.traitsOfFont(font), weight: weight, size: font.pointSize) {
self.font = font
}
}
}
If you don't really care about the styles, use regular weight font for all text, it should solve the problem, see my earlier answer for available options.

How to implement a dock icon notification indicator with Electron in OS X?

I don't actually know the thing's name, I am talking about the red dot on the right top corner of app icon.
I'll have to make some assumptions here because I don't own a Mac to test this with. I believe that those red dots on the corner of an app icon are referred to as badges. In Electron's App module there are methods to get/set the badge along with other dock features. Check out http://electron.atom.io/docs/v0.30.0/api/app/ for more information. Here are the relevant methods:
app.dock.setBadge(text)
text String Sets the string to be displayed in the dock’s badging
area.
Note: This API is only available on Mac.
app.dock.getBadge()
Returns the badge string of the dock.
Note: This API is only available on Mac.
My guess is the code to produce the dot that you see in the example from Slack that you provided would look something like this:
var app = require('app');
app.dock.setBadge('.');
you can also try this
app.setBadgeCount(numberOfNotifiations)
What I usually do is simply increase the current badge count by 1, like so:
app.setBadgeCount(app.getBadgeCount() + 1)
see https://electron.atom.io/docs/all/#appsetbadgecountcount-linux-macos

Resources