Label and NSTimer shadow design - ios

I'm a beginner in iOS and need some leads to do something that don't feel that easy to do ...
I have to change my design for a timer (elapsed time and remaining time) that looks this way :
To something that look this way :
Would you have any leads to give to me (except for the shadow color and offset properties that I already know) ? My principal guess for now is : How differentiate these 2 states : gray when no time and blue when there is.
Thank you in advance !

You're new to iOS development, so i'm not sure if it's a good idea to throw some 3rd party framworks at your head! but anyway, take a look at TTTAttributetLabel. I'ts a drop-in replacement for UILabel and lets you style the parts of a UILabel text differently, so it could fit for your needs above!
Download the framework from the given link and look at the example project provided with it. And don't forget to include the CoreText framework into your project. (see "How to add existing frameworks in Xcode")

Related

Text view with rich markdown in SwiftUI (more than only bold and italic text)

Android
In my app I need to visually style and highlight long texts that come from a DB. The texts are written as following:
Accept the <f>current</f> situation and <f>then</f> try to build a better one on top of it. Only then will you catch a break from all that getting away and will be able to think about how to actually improve.
<h>Resistance deepens the negative thoughts, acceptance releases them.</h>
On Android, I take these texts and parse them using Regex to replace the tags with something that works with the library. I'm using the SRML library to display it like this:
iOS
Now my question is: how do I reach a somewhat similar experience on iOS?
I'm using SwiftUI so far, but I can see that it's pretty limited in this specific regard. All I've found so far are libraries that helps you make it bold, italic or something other very minor:
https://github.com/kyle-n/HighlightedTextEditor
https://github.com/indragiek/MarkdownTextView
But I specifically need to highlight phrases, meaning color their background yellow. I then found this library, that offers some pretty complex functionality, but is written in Objective-C and I don't know how well that will work with my SwiftUI basis: https://github.com/ibireme/YYText
Is there any chance for me to get it working with SwiftUI components?
My best guess would be to do something like this (very basic pseudo code):
text = DB.getText
parser = StringParser(text)
content = ViewGroup()
while(parser.hasNextLine) { nextLine in
if(nextLine.contains("<h>")) {
var text = Text(nextLine)
.background(Color.yellow)
content.add(text)
} else if(...) {
...
}
// etc. etc.
}
And kind of build the resulting Text step by step from multiple pieces. But this looks kind of ugly to be honest. Any other ideas? And if not, how should I go about including that Cbjective-C library into a SwiftUI project?
With the help of a freelancer on Fiverr I solved it in the following way:
https://stackoverflow.com/a/69871902/1972372
Basically parsed the tags manually and kept track of the content types and order in an array, while keeping formatted Texts in another array. Then I could take that content and plant it into a ViewBuilder body function.
Unfortunately, SwiftUI doesn't let you change a Text's background color yet, without turning it into some View. So I had to make do with other, similar formattings for now.

Adding array of UIImage in a UIViewController with some alignment

I just started my first project in iOS, recently I have encountered a problem in the UI when i receive it from the designer.
The expected output is shown as below and i can do most of it without any problem.
Now the problem came when I am about to implement this :
As the number of colour varies depending on item, I cannot add it like what I did for the share and love button I have no idea how can i implement something like this, I have look through the Object Library in the storyboard and cannot find any that can produce the output as expected .Any helps and guides are much apprecited!

Xamarin.forms and immediate mode graphics

Does anybody know how to draw immediate mode graphics into a xamarin.forms view?
I need to draw some app specific graphics into a form. I've been googling and looking at examples for a lot of the day. I know about Renderers. I can almost do it, but ViewRenderer can't be easily subclassed (unless I'm missing something), and I can't find an existing view subclass that is suitable.
Sometimes my own stupidity and thickness surprises even me.
The answer is to create a concrete, OS-dependent View for each platform. Then create a ViewRenderer implementation for each platform.
The platform-specific ViewRenderer<...> then instantiates the platform-specific view. And we're off to the races.
There are minor details, such as how to communicate or acquire view size and parentage, but at least those are known problems.
So, you have the following components:
A MyXamarinFormsView, which sub-classes Xamarin.Forms.View. MyView doesn't actually have to contain any significant logic. Think of it as a placeholder.
For each platform:
A MyXamarinFormsViewRenderer : ViewRenderer<MyXamarinFormsView, MyPlatformSpecificView>
Add the following attribute instance to each ViewRenderer, after any using statements and before the namespace declaration (if there is one):
[assembly:ExportRenderer( typeof( MyXamarinFormsView ), typeof( MyXamarinFormsViewRenderer ) ) ]
A MyPlatformSpecificView : platform-specific View (e.g. UIView for iOS)
Put the graphics-specific code in each platform-specific view subclass.
I'm not certain if this is the official/correct way of doing it, but it does appear to work for me.

Edit exisiting class propertys or make system wide changes to a class

I have problem with iOS 8 and the SKLabelNode Class.
I used in my Project lot of SKLabelNodes(We speak about 120 nodes) and in iOS8 Apple has changed the built in FontType and now all my Labels hardly readable. I would like to change back, but I dont want to edit all the Nodes by one. I would like to change the SKLabelNode Class Defaults Font type. Is it possible? Or any other solution?
Sounds like your best bet would be to use a category Apple Category Docs
Or take a look at swizzling. There's a good tutorial here Swizzling
I think your best bet is actually method swizzling to replace the getter or modify the category to add a new init that sets a default font. Hope this helps.

invert UIDatePicker colors in iOS 7

I want to start by saying that i would post this question on the Apple Dev Forums but because of the hacking attempt fiasco , or whatever that was, the forum has been offline for almost 2 weeks now and i need a solution for this as soon as possible.
In iOS 7 the UIDatePicker looks like this :
and a client asked to look like this :
(basically inverted).
I've tried a few things:
Setting the background to black and looping through all the view's subviews until i reach the labels that show the date itself and change their color to white. The problem is that The view has only one subview, and that subview doesn't have any subviews of it's own. So this solution doesn't work. (it did in ios6).
Applying a filter to the view's CALayer. The thing is that this is only possible on OS X not on iOS, for some unknown reason.
Playing with UIApperance protocol. From what i've read this should work but what i've tried didn't and i don't have extensive experience with this to figure out why not.
Any ideas what i can try? Is this even possible? Did i made a mistake in my approach of the problem?
Try this out :
Put this code in -(void)viewDidLoad
[datePicker setValue:[UIColor whiteColor] forKey:#"textColor"];
Swift:
datePicker.setValue(UIColor.white, forKey: "textColor")
Don't know if this is still relevant but on Swift 3 / Xcode 8 you can simply do this:
let datePicker = UIDatePicker()
datePicker.datePickerMode = UIDatePickerMode.date
// Sets the text color
datePicker.setValue(UIColor.white, forKey: "textColor")
// Sets the bg color
datePicker.backgroundColor = UIColor.black.withAlphaComponent(0.6)
textField.inputView = datePicker
I spent quite a bit of time struggling with the same problem. At first, I've put a UIDatePicker on a black background and was wondering why it is invisible...
I ended up placing a white UIView as a background for the date picker, so while the whole view is black, the date picker is white. It actually looks okay, although thankfully I don't have a client who would dictate the design.
One possible argument for a client: the old, pre-iOS7 date picker, also had a predefined non-customisable background.
What you want is possible, but it will be called Custom Date Picker.
Below is the link where you will find what you wanted.
https://www.cocoacontrols.com/controls/simpledatepicker
If you need more, take a loot at below link.
https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=datepicker
Well I understand your frustration, but iOS7 is under NDA. Usually this kind of views are made using layers, beacuse of sublayerTransform that can make perspective giving the idea of 3D. I would check sublayers if you don't see subviews.
The other poin is that I would not hack too much views/layers hierachy, ios<=6 to ios7 transition shown that hacking isn't a good idea.
UIAppereance protocol is probably the way to go, becauase it makes you change what you can change (without screwing that in the future), maybe you can set a backgroundImage, try to set a 1x1pixel of a blck color png, you should also see an attributed string property, or text property.
I dont think its possible to do that directly by changing the properties of the default UIDatePicker , although you can use custom controls to do it.
This might help,
MWDatePicker - https://github.com/mwermuth/MWDatePicker (Found it in cocoa controls -https://www.cocoacontrols.com/controls/mwdatepicker)
according to the iOS Design Resources:
You cannot customize the appearance of date pickers.
I would suggest one of the below:
Redesign your UI to use the black text
Use a customer datepicker
You should tell your client that his suggestion is against the design principles of iOS 7, which indeed it is. I am not a great fan of iOS 7 myself, but we should all give it a go. Your client should accept the standard iOS 7 UI provisionally, until he is in a position to make an informed judgement. Designing an app based on his initial impressions is a recipe for disaster.

Resources