Monday, November 11, 2019

Avoid Wrong Height UITableView When Reload and Add New Row


I have a problem where I can't find the solution on the internet like google, stackoverflow and blogs. So I need to trick this so that It work like I want. It's like the bug from iOS because what's supposed to be i'm doing it's the correct way. And the error seems weird because it's only sometimes happened.
I try to find it by way and it takes long time. And finally I got the solution but I think it's not final solution but I hope iOS will fix the issue soon.

So the error it's when you first time entering UITableview.  If you dynamic height like instagram did, you will sometimes get wrong height. But if it's not you are saved. I don't know if this problem only happened to me or not but after a few years expierence. I think this bug happened not only me.

My solution is not the best but I think it's really good to hide the pain because of this annoying bug haha. What I did is to refresh three times refresh when first reload UITableview. So if you have opened the UITableview before don't need to recall it again. Because it will make the memory bad.

Tuesday, November 5, 2019

Add Loading ActivityIndicator in AVPlayer Video iOS Swift 5



This week, I want to show loading after I have a video player that uses AVPlayer library. If you're curious like me. Stay tuned in this blog or if you're in hurry just scrolling on bottom. I must've given the source code. If you're an expert it must be easy to follow.

So if you don't use playback controller library AVPlayerViewController. I mean maybe you use AVPlayer Layer. It's basically it doesn't have playback controls. It's good to use loading Activity Indicator so the user will have a good expierence to operate our app.

So basically the AVplayer itself has a loading indicator beside play/pause button as you can see on above image. But it's not enough for me because it's too little, I need something on center like I do in UIImageview or loading something like loading API.

And the problem with AVPlayer, it doesn't have delegation to perform loading action so we need to use observer to do it. And don't forget to add the ActivityIndicator itself. Define it on public class but it doesn't matter if it is in method class.


Tuesday, October 29, 2019

How to get thumbnail from video URL in Swift 5


If you want to show video in your app and you want to show thumbnail. The easy way is to get image url from server API. But there is more easy way you just need to get url video and get image url. I have searched on the internet but what I found my app becomes lag. I use UITableview to show the video thumbnail url.

Maybe you wonder why I use image thumbnail. I can use video player from iOS and thumbnail video will be shown. But what if you use many thumbnail in UITableview, it will be heavy in the device. It's bad design too.

It will be good for you, if you can combine this extension image with SDWebImage. Because the image will be in cache and you don't need to reload image again. But you still need the internet to load the video url. Because it's online from the internet.

This is swift code and about objective-c code, it's better you search on the internet. I know it's really painful to change it to swift if you have developed big app. So you can convert swift to objective-c but it's not sure there will be a match library between swift and objective-c.

Tuesday, October 22, 2019

Create Rectangle Bubble Chat iOS Swift 5


Hello all, every week I try to give you a good tutorial to add your skill and knowledge too. And today you got to be suprised because It's not usually tutorial. I need to dig it deep down to present it. So if you want to create chat application, it's good for you. You can take it as reference.

So in chat application, you will face chat from bottom to up. As a screenshoot above, you can see it's not from top to bottom but otherwise. There is bubble chat on left and right. You can say when you send it will be on right and when someone send, it will be on left.

And about text height, it must be flexible height. Like app chat line or whatsapp, there is no cut in height. So it can small or so high. So we need to calculate the height. And about the width it's not full, we give space to the right or left.

I include the title header too so It will be more like chat app. The header will be on viewForFooterInSection why ? Because I reverse the UITableview, so the chat will be on bottom to top. As you can see on image above.

I create UIlabel date after message like chat app usually. So it will be complete for you to implement. And sorry if I don't give you full Source Code because it's easy to follow when you the code. So this is the code..

Wednesday, October 16, 2019

Double Tap Zoom to The Tap Location Swift 5 iOS 13


Hello, I find a problem where user wants to zoom to the tap location in ImageView. Actually ImageView inside UIScrollview. Because it's not just zoom when double tap but user can zoom manually with pinning. So basically it's like gallery album in iPhone, you can see it.

When I try find the way on the internet, it doesn't work like the way I want. Double tap to zoom working but it just zoom on the center not to the tap location. You need to combine UIScrollview with UIImageview to use gesture zoom. Because UIImageview itself doesn't use scrollview so it will not effect scrollview.

Maybe in iOS version before 13 the way on the internet it works. Because I see some posting get upvote and every comment say it works. But in new version of iOS we need to check again. So it's like swift version language. It has developed better again.

So I finally combine answer on the internet to make what I want. So  this is the code


Tuesday, October 8, 2019

Avoid Create Multiple Album in iOS Swift 5


Do you ever have an application that can download photo from your app to your album gallery ? It's not so complicated to do it, if you have the library that I will share to you right now. When you save your photo sometimes you need to create the album first then put the images in there. So It's neat too look. You can name your album with name of your app name.

So the trick is everytime user will download you call create album method. In this method you check first if there's an same album created or not. If it's not then creating new one otherwise don't create. Because in iOS create same name, it's permitted. So it will be bad if you create many albums with same name.

And if you reinstall the app, maybe the app will create the same album if you don't check. So it's our job as programmer to handle it. To make the user doesn't need to delete the same album. I personally want to know the way before I didn't reliaze that my app create multiple albums after I check it manually. So after I found it multiple, I try to find the way on the internet and finally it's not hard to do.


Tuesday, October 1, 2019

Solution UIViewController Not Full Screen in iOS 13 ( Bonus My Extension )


Good october month all.

Have you installed iOS 13 in your device and you get suprise that some of your views have a gap on the top like picture above. It's bad or good news for us developer iOS. First it looks new and some people may love or hate it but in iOS 13 it becames default system to use it. You need to change it manually every view controller, if you have many it becames many job to do it.

Why we need to change it back to fullscreen, because I have view that has not to come back to previous view. It will be bad for user expirience to swipe up and go back and what they get only splashscreen and don't go anywhere again. It needs to reopen app again. This is my case in my apps.

Fortunely it's not hard to change it back to fullscreen again. It just needs one line code to change it but if you have function everytime you do presenting view controller. You just need to add one single line to make it fullscreen but if you have many present function in many classes. Good luck for you to change it one by one ok.

So this is the code you have to add. Of course you can find it online by google, but i need to tell you the best way is you use fullscreen. And I will give you my extension to present and dismiss with animation. Here we go...

Monday, September 16, 2019

How to customize your date according to Timezone in Swift 5


What if we want to unite time in different country for all users that install our app. Yes we can use one timezone for all users. Example we use Asia/Jakarta timezone then everyone who install our app will get same time. But you have to work together with your API developer, so API will send same timezone to all users. And in our app we will get it and convert it. It's not difficult to do it. I will show you how.

I use swift 5, because that's latest one. I haven't used objective-c because no project that write use it. Swift actually more simple than objective-c but it's same. It uses iOS OS. Xcode is helpful tool to write iOS app. But if you use xamarin, it will be ok but the language is not same at all. You need to research again.

You need to understand basic thing about timezone. What is your timezone in your country ? you need to know UTC and GMT because iOS use these.

Thursday, September 5, 2019

How to disable UITableview ScrollView Pagination when Data is Still Fit In


Hello guys, if you ever work with UITableview. Sometimes you need to do pagination and there many ways to do it. One of them is using scrollview. I want to share with you my improve way to do pagination because on the internet. It needs to improve a little bit.

Why you need to do pagination because it will make your app run lightweight and more fast. Because you just load API as necessary. Many greats app use this and if there are images you don't load all. It's just load the first page one.

Fortunately iOS support it and we can use UITableview to do it. UICollectionView can do it too but we talk it later on the next post.

So check this out.

Wednesday, September 4, 2019

How to disable touch outside to dismiss and swipe in Side Menu Swift


I find a problem where I need to disable side menu to dismiss. So basically it's just showing side menu and view controller behind it. I use library https://github.com/kukushi/SideMenu because I look it simple and it support swift 5.

I need to custom it because in my side menu I have parent and children so I need to customize it manual. But in here I don't tell you how to do it because my focus is to disable touch outsude and swipe. Sometimes you need to do it in some UIViewController. And Side menu library don't explain it explicitly. So I need to figure it out by myself and it's not harder to do find it out.

In Side Menu it works with gesture so I need to get all gesture and disable it according to what I want to disable. In this case swipe gesture and touch outside. You can see in my code I put it in ViewDidApper and ViewDidDisappear because I just want disabled feature in this only UIViewController.

Sunday, August 11, 2019

How to set first day of week in DateRangePicker Calendar Android


I have created an app called "To Do List Extra" that has a calendar. I found a issue that i need to set first of week to saturday or monday. By default calendar will be sunday. So i tried to ask on the internet and finally found the way. Locale will make a different first day of week. I just changed the locale and automatically the first day of week will be changed too.

Why I need to set first of week because in different country we have diffrent first of week. In my country first of week is monday. It's very helpful we don't need to adjust the calendar. DateRangePicker is default Android library so it's not complicated to customize it.

In my app We have to add task and put date and time if you want. I have notification timer so it will put banner notification when your task date and time is suitable with time right now. So basically it's important to set first of week.

Thursday, April 11, 2019

Problem UICollectionViewController When Trying to Use bringSubview Swift 4

Hi guys, I found unique issue when trying to use bringSubview in UICollectionViewController. The method doesn't work if you try like this.

UICollectionViewController has a diffrent to do add subview. Because it's not pure UIViewController itself or parent. It needs to get superview to add a new view.

So basically you do like below and nothing happened or it doesn't work. Don't worry about it, i have a solution for you. It's simple way to do it and don't make you think too much. I find this idea on stackoverflow. I will put the link below.


self.view!.addSubview(something)
self.view!.bringSubview(toFront: something)

So to do trick you need to use superview!.

Saturday, March 9, 2019

Change status bar text to white iOS Swift 4.2 Xcode 10.0

Hello back guys, I'll show you guys how to change status bar text without coding. Just follow this screenshoot that I give. It's a peace of cake and you don't need to confused about it. I will tell you  simple way. But it's good to do programtically, it's just an option.

Why we need to change status bar text because we sometimes need to costume our application with our theme. If you have good theme, customers will like you app and use it every time haha.

You need to edit Info.plist to do it but xcode will do automatically if you change it Deployment info because it will change Info.plist when you edit it. I will give you a source code too what will change in Info.plist.





Source code in Info.plist

Thursday, February 14, 2019

Trick to Avoid Force Close Because of JSON Null Swift 4

Hi guys today I'm gonna share to you my extension to handle JSON null. You can change return default. So your app will never be force closed because of JSON null. So this is the code.

Sunday, February 10, 2019

Extension Rotating Image Smoothly with Swift 4

Do you ever want to do animation thing like rotating image continuously ? Today I want to give you a good way to do it. I make this a extension so it's easily to maintain :D. I found this trick on stackoverflow and implement it using swift.


Saturday, February 2, 2019

Get Height Keyboard iOS Swift 4

I have a problem when trying to use IQKeyboardManager. When keyboard show up, the navbar sometimes will break the top and give some white space. So finally i turn off IQKeyboardManager and trying to implement keyboard show up by self. So the point is to get height keyboard and raise the textbox above keyboard. This is the example of I've done.

Wednesday, January 30, 2019

How to convert HEX RGBA color in swift 4.2

Hello guys, today I wanna share with you a method or extenstion that I use to convert any hex rgba like this #33000000 which is One hash and 8 digit hex. 33 is for Alpa, 00 is R, 00 is G, 00 is B. You can modify the code appropriate what you want. So the code goes likes this.

Monday, January 21, 2019

Don't Use prefs:root= in Your iOS Apps

My client got an error when trying to submit the app to app store. So the message goes like this :

Guideline 2.5.1 - Performance - Software Requirements



Your app uses the "prefs:root=" non-public URL scheme, which is a private entity. The use of non-public APIs is not permitted on the App Store because it can lead to a poor user experience should these APIs change.

prefs:root=wifi

Continuing to use or conceal non-public APIs in future submissions of this app may result in the termination of your Apple Developer account, as well as removal of all associated apps from the App Store.

Wednesday, January 16, 2019

Create Colored Clickable Link Between text in UIlabel Swift 4.2

Happy New 2019 although it's too late but i finally get a topic about what I want to post today. I have a solution for you guys who wants to make clickable link check it out. See this image when you click the link that has purple color you will redirect to external browser. I'll share the code, dont' worry :D