Posts

Post not yet marked as solved
23 Replies
4.6k Views
I am working on a custom UIView class called TrackerView that basically builds a FedEx style tracker to display the progress of a manufacturing procedure. This entire view is based on custom drawing code inside the drawRect method of TrackerView. The tracker is up and running and my next problem to solve is how to make my custom view work with AutoLayout to handle things like landscape and portrait orientations, etc.I'm trying to learn this stuff, so if anyone has any resources or materials that they can point to on where to get started with AutoLayout as it pertains to custom drawn views in particular... that would be great! Any sample code or example code of how to handle custom drawing and layout changes would be an immense help as well!Thanks.
Posted
by mkhan094.
Last updated
.
Post not yet marked as solved
2 Replies
906 Views
This inspired from some of Apple's UIKit controls that come as part of Xcode Interface builder such as UIPickerView. When I drag a UIPickerView into my scene, you get a placeholder image that says "Cupertino, San Francisco, Montainview, Palo Alto" etc. Those elements are not editable its just a nice placeholder that way you dont have this big blue square that says UIPickerView. I have a UIView Class called ProgressTrackerView and I have a placeholder image of a progress tracker UI... is there a way I can see that placeholder image in Interface Builder but when I run my app... the actual prgress tracker with real data appears instead? Eventually, if we ship this as library for others to use, it would nice to have something there. I looked into IBDesignables, however, IBDesignables fail to render UIImageViews with images, so thats not a viable solution.
Posted
by mkhan094.
Last updated
.
Post marked as solved
4 Replies
2k Views
I have a UIImageView in which I want to put an image. By default the image in the imageView will go edge to edge and cover the entire imageView. What I want to do is inset or "shrink" the image so that it sits inside the imageView with a nice padding. Any guidance on an approach for this would be appreciated! Thanks in advanced..Please see screenshot for intended output: h ttps://drive.google.com/open?id=1IxJ48By22t-7qHBOf5zuKpT6MzaaNPVT
Posted
by mkhan094.
Last updated
.
Post marked as solved
11 Replies
822 Views
Illustration link: h ttps://drive.google.com/file/d/1xwrbqYs87wtksupbXHFI_vDXZ_OHvvKC/view?usp=sharingOver the last couple of days, I have been working on a progress tracker class / UI (see link above for illustration) that will be used to keep customers updated on the status of their order. One of the problems I am trying to solve is how to update the progress tracker based on a response from the server. So far I have mapped it out to the following ( my illustration above actually has this mapped out in more detail, please take a look, I think it will help explain it clearly)Essentially I have:1. An image library array that stores the images for the different stages for the progress tracker2. An UIColor array that stores the colors that the image can be (for example, the "Build" image can be green meaning the product has been manufactured, or yellow meaning the product in in manufacturing.3. The progress tracker will be updated based on a respone from ther sever, so if the server sends back [0,1], the approriate image from the image array and the corresponding color will be applied to it and then the progress tracker would update with the image and color.Again, my lllustration maps it out more visually and it has a method I am working on... I would appreciate any advice on how to make this work or even if I'm on the right track. I'm thinking about using a dictionary, I also research into using the Set collection type, but I dont know if that's the right approach.Thanks!
Posted
by mkhan094.
Last updated
.
Post marked as solved
4 Replies
681 Views
I am trying to apply a tint color on a set of UIImages that I have and I came across this neat implementation online that I am trying to understand. My question is about line 2 and line 27. Thanks in advance!Line 2: What is the syntax in the parameters list? This is something I haven't seen before... Line 27: This type of return statement is also new to me, I'm guessing its related to the special syntaxt in modifiedImage?// What is the syntaxt in the parameters list? Never seen this before.... private func modifiedImage( draw: (CGContext, CGRect) -> ()) -> UIImage { // using scale correctly preserves retina images UIGraphicsBeginImageContextWithOptions(size, false, scale) let context: CGContext! = UIGraphicsGetCurrentContext() assert(context != nil) // correctly rotate image context.translateBy(x: 0, y: size.height) context.scaleBy(x: 1.0, y: -1.0) let rect = CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height) draw(context, rect) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image! } func tint(tintColor: UIColor) -> UIImage { // Never seen this type of return statement... maybe if in understand the private func uptop, then // this will make sense... return modifiedImage { context, rect in // draw black background - workaround to preserve color of partially transparent pixels context.setBlendMode(.normal) UIColor.black.setFill() context.fill(rect) // draw original image context.setBlendMode(.normal) context.draw(self.cgImage!, in: rect) // tint image (loosing alpha) - the luminosity of the original image is preserved context.setBlendMode(.color) tintColor.setFill() context.fill(rect) // mask by alpha values of original image context.setBlendMode(.destinationIn) context.draw(self.cgImage!, in: rect) } }
Posted
by mkhan094.
Last updated
.
Post marked as solved
4 Replies
2.7k Views
I think this is one is fairly easy one since it has to do with simple logic, but I can't seem to figure it out. So I have two arrays:1. An array of images2. An array of imageViewsFor simplicity sake, the number of images and imageviews will always be the same. What I want to do is for every image, assign it to a corresponding imageView in the same index in the imageView array. Here is my code... I was trying to use a for in structure, but I'm not sure if this is the right way to go. Any advice on this would be great! Thank you.// progress elements are imageViews // Assuming method is already been implemented after this declaration to specify // the number of progressElements in the array var progressElements = [UIImageView]() // Assuming image1-4 have been declared already var progressElementImages = [image1, image2, image3, image4] // Method that accepts an array of UIImages and then assigned func setProgressBarElement(images: [UIImage]) { for element in progressElements { element.image = images[???] } }
Posted
by mkhan094.
Last updated
.
Post not yet marked as solved
1 Replies
1.9k Views
Is anyone having issues with the peformance and usability of Xcode Playgrounds? I am having several issues:1. Super slow and laggy (i expect the usualy 5-7 seconds for compiling, but staring at the screen for 3 minutes is way too much)2. Built in templates (Single View playground) does not even compile (bad execution error)3. Errors show up in the navigator but they dont appear inline in the playground fileI have filed a Bug Report with Apple, but I'm just trying to figure out if this is problem people are facing with Playground recently. I love playground for prototyping, but with this current version, its way faster to write code > test in simulator > and re-iterate.
Posted
by mkhan094.
Last updated
.
Post marked as solved
3 Replies
660 Views
Hi,I am working on a iOS application for a medical device company. Just like for any software project we have design requriements and design specification. Additionally, since our app will fall under FDA's rules, we have some extra work to do in this area. One of the things we would like to do have some kind of way in Xcode to be able to link specific source files, classes, methods, etc. to design requirements... for example:Design Requirement # 1:User must be able to signup through our app and credential are generated on ther severRelated Source Files / Classes / Methods to fulfill design requirementsTextInputValidation.swift validateUserEmail ( ) validateUserPassword ( ) registerUser( )I'm fairly new to this and still researching this, but is there a way, to do this in Xcode or some other tool? Currently, I am thinking about just adding comments inside class files at the top or for a method with someting like "DR001" or something, but if someone has come accross a more elegant and purpose built solution. Our project manager and I myself would like to have a cool way to do this... I was thinking about building an Xcode Source Editor extension for this, but I dont know if a source editor extension makes sense?Thanks!
Posted
by mkhan094.
Last updated
.
Post not yet marked as solved
2 Replies
553 Views
I have a problem that I am running into when working with segues, storyboards, and IBActions. I have a SignUp Form with several text fields and UIButton for signing up. Basically, when the user taps sign up, the application will validate the text fields and then basically add that user to my database backend like FireBase. Also, if the signup was successful, I segue into another View Controller that says Welcome.. otherwise a UIAlert will be displayed and the segue does not happen. The problem is that even if the user didnt enter the correct info the welcome segue still happens. Here is what I've done:1. Control Drag UIButton to WelcomeViewController and set the segue identifier to "welcome"2. Made an IBAction method for the UIButton. See below:I think my problem has to do with with my storyboard connection, but I'm not sure... @IBAction func registerPerson(_ sender: UIButton) { // BASIC CREATE USER CALL, THERE IS MORE TO THIS, BUT THIS JUST A SUMMARY OF THAT PORTION createUser() // Code for server. If data was not enetered in the database, then a UIAlert is displayed if response.result.isFailure { let alert = UIAlertController(title: nil, message: "Unable to register", preferredStyle: .alert) alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_) in alert.dismiss(animated: true) })) self.present(alert, animated: true) } else { // Perform segeue self.user = response.value! self.performSegue(withIdentifier: "welcome", sender: self) } } } } Thanks,
Posted
by mkhan094.
Last updated
.
Post marked as solved
4 Replies
2.4k Views
I'm working on text field validations specifically with regards to validating an email. I did research online and the most common solution seems to be to use the NSRegularExpression Class followed by using NSDataDetector. I've seen videos and examples on using regular expressions, but the code for it seems very confusing and the videos dont explain the actual code, rather just show it working... The most confusing part is this. If anyone could provide guidance on this topic that would be very, very helpful!// QUESTIONS // What is A-Z0-9a-z. etc.... // What is the {2, 3} at the end.. let emailRegEx = "[A-Z0-9a-z.-_]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,3}"Thanks!
Posted
by mkhan094.
Last updated
.
Post marked as solved
35 Replies
4k Views
REFERENCE SCREENSHOT:h ttps://drive.google.com/file/d/1rQ9qZPNoFGCfEndGOEbYLfsIET7TYuEf/view?usp=sharingHi,I am working on a simple form with 5 text fields and a UIButton, particualry the the titleLabel.text property of the that button. What I am trying to do is to peform a check when the user hits the SignUp Button (see link for screenshot). So when the signup button is tapped, I want to run a check to see if:A. Any of the text fields are empty (thinking about using the isEmpty property)B. If the Button Label text is still "Tap to choose a role..." If the user selected a role by tapping the button, this text would be replaced by the role which confirms that the user selected a role.When the check is peformed, if any combination of empty textfields and/or button labels are "invalid" (i.e empty or incorrect label), then I want to display a UIAlertController and the message parameter of the alert would show the textfields and/or button combos that need to be filled.Any guidance on how to begin would be great, there are so many combinations, that could be possible ( 1 text fields, 2 textfields + button, just the button, etc). Here is my current code, but I dont wanna go down this route since that would be a lot of code writing and its probably not the best solution but a start...// IBAction function for when the user taps sign up button @IBAction func whenSignUpButtonIsTapped(_ sender: UIButton) { //Workflow // 1. Validation check // 2. Register User // 1 validation check... if (firstNameTextField.text?.isEmpty)! { let missingInformationAlert = UIAlertController(title: "Missing Information", message: "First Name is required", preferredStyle: .alert) let cancelAction = UIAlertAction(title: "OK", style: .cancel, handler: nil) missingInformationAlert.addAction(cancelAction) self.present(missingInformationAlert, animated: true, completion: nil) }Thanks!
Posted
by mkhan094.
Last updated
.
Post not yet marked as solved
9 Replies
7.7k Views
I had a question about Auto Layouts in Xcode. I've started to get the hang of this system and so far it is working pretty well. The only problem I am trying to solve is related to my UITextFields and UIButtons in my login screen. Currently, my auto layout constraints are set that the the textfield gets stretched out iPad. My ideal layout is to have the textfields be the same size as they are on iPhone and still centered on the iPad display... Please see accompanying screen shots for reference. I've tried many Interface Builder Constraint combination, but I cannot figure out the correct one? Any help would be appreciated.Screen Shots1. Current Auto Layout - i.stack.imgur.com/EABr6.png2. Intended Auto Layout - i.stack.imgur.com/K2K0b.pngThanks,
Posted
by mkhan094.
Last updated
.
Post marked as solved
2 Replies
769 Views
I'm working on a table view where I want to use the UITableViewHeaderFooterView class to customzie my headers and reuse them for several sections in the table. I am trying to understand what the logic for this code is:override init(reuseIdentifier: String?) { super.init(reuseIdentifier: reuseIdentifier) }From the reference docs, I understand what the method does, what I don't understand is the line of of code inside the methodsuper.init(reuseIdentifier: reuseIdentifier)I've seen this from time to time as I have been learning iOS development, any explanation of what super.init is doing would help. It seems redundant, but perhaps because I don't understand the logic begind this. Thanks!
Posted
by mkhan094.
Last updated
.
Post marked as solved
2 Replies
1.2k Views
I'm very new to JSON and parsing jason. I have watched some tutorials and it seems like Swift 4 makes JSON parsing quite easy. I am currently working on a project in which we want to build a task tracker. The idea is that we will have a task list (UITableView) with things such as name, owner, status etc.My question is: Can a JSON file be "live file" i.e. if new tasks are added, they would automatically get populated in the JSON and those new tasks would appear in the tableview? Also if anyone has any resources that they can point to about learning JSON that would be great!
Posted
by mkhan094.
Last updated
.
Post marked as solved
1 Replies
2.2k Views
I am working on an app in which I want to embed a UISplitViewController in a Tab Bar Controller. Bascially, when you click on one of the tabs, a UISplitViewController will appear where users can select a case from the master view and view the details in the detail view. I came accorss the following note in UISplitViewController's documentation:Although it is possible to install a split view controller as a child in some other container view controllers, doing is not recommended in most cases.I am tryintg to understand the logic begind this advice:Why is not recommended in most cases?Which cases is it okay to break away from this general advice?The iTunes U App seems to have a SplitViewController inside a tab bar controller and its quite prevalent, it seems to be breaking away from the advice (maybe for a good reason that i dont know)?
Posted
by mkhan094.
Last updated
.