Mandar Apte

UI/UX Designer from Mumbai, Maharashtra, India.

Category: Code Examples

  • Stop OpenAI’s ChatGPT User agent from scanning and using your website’s content.

    Stop OpenAI’s ChatGPT User agent from scanning and using your website’s content.

    Background:

    Wikipedia Describes ChatGPT as an AI chatbot developed by OpenAI. ChatGPT is an artificial intelligence (AI) chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI’s GPT-3.5 and GPT-4 families of large language models (LLMs) and has been fine-tuned (an approach to transfer learning) using both supervised and reinforcement learning techniques.

    ChatGPT can access real-time info from the web using plug-ins.

    If you don’t want the ChatGPT User-agent to use your website’s data, you can block it using your robots.txt file.

    A ‘robots.txt’ file is generally located at the root of the web server and can be accessed using SFTP or can be viewed using this URL:

    https://yourwebsite.com/robots.txt

    (replace ‘yourwebsite.com’ with your domain name)

    You need to add this rule to your website’s ‘robot.txt’ file

    (more…)
  • Removing the Title Bar from the Mac Catalyst App

    Removing the Title Bar from the Mac Catalyst App

    Learn how to remove the title bar from your Mac Catalyst app.

    We are using Swift Programming Language.

    The code will look something like this:

    
    #if targetEnvironment(macCatalyst)
        if let titlebar = windowScene.titlebar {
            titlebar.titleVisibility = .hidden
            titlebar.toolbar = nil
        }
    #endif
    (more…)
  • Apply UIVisualEffectView & UIBlurEffect to any Views in iOS / iPadOS or macOS app.

    Apple describes UIVisualEffectView & UIBlurView in its support document as follows:
    Depending on the desired effect, the effect may affect content layered behind the view or content added to the visual effect view’s contentView. Apply a visual effect view to an existing view and then apply a UIBlurEffect or UIVibrancyEffect object to apply a blur or vibrancy effect to the existing view. After you add the visual effect view to the view hierarchy, add any subviews to the contentView property of the visual effect view. Do not add subviews directly to the visual effect view itself.

    In other words, you don’t have to use Adobe Photoshop to get a blur effect and fake superimpose it on your UIView. Instead, you can programmatically get the same effect for every situation without hassle.

    Note: If you are using UIVisualEffectsView in your app, I would strongly suggest you use a system setting called ‘Reduced Transparency’ to condition code it. If the user doesn’t want transparency, Blur, or Vibrancy effect for all of the apps on his iPhone, iPad, or Mac, he can do it with a single switch in the settings app. Another note view that you are applying effect should preferably be the Popover View Controller. Another thing to remember is to replace the blue color below with the UIColor of your choice with alpha channel transparency.

    For UITableView and UITableViewCell, use the following code in your UITableViewController’s viewWillAppear function:

    (more…)
  • Add a mouse hover effect / UIPointer Interaction to any iOS or iPadOS app views.

    Add a mouse hover effect / UIPointer Interaction to any iOS or iPadOS app views.

    As Apple describes Pointer Interactions in its support document:

    Pointer Interactions: Support pointer interactions in your custom controls and views.

    iPadOS 13.4 introduces dynamic pointer effects and behaviours that enhance the experience of using an iPad with an external input device, like a trackpad or mouse. As people use an input device, iPadOS automatically adapts the pointer to the current context, providing rich visual feedback and the precision needed to enhance productivity and simplify everyday tasks.

    Note:
    UIPointer Interaction is only related to the iPad / iPadOS app

    Initial Step:
    Add ‘UIPointerInteractionDelegate’ in your View Controller’s Class Declaration

    For UIButton:

    Out-of-Box Implementation:

    
    button.isPointerInteractionEnabled = true
    

    UIView and Custom Implementation for UIButton:

    (more…)
  • Get the iOS, iPadOS, and macOS operating system names, versions, and model identifiers programmatically.

    Get the iOS, iPadOS, and macOS operating system names, versions, and model identifiers programmatically.

    Programmatically get iOS, iPadOS, macOS Catalyst Operating System Name and Version and a model identifier of iPhone, iPad, and Mac devices.

    Here is a simple way to programmatically get the operating system name and version of your iOS, iPadOS and macOS.

    The code below will also return the value of the iPhone, iPad, and Mac Model identifiers to help you determine whether the device is a MacBook or iMac in a Mac case, an iPhone 11 Pro, or an iPhone 13 Pro.

    Step 01:
    First, import IOKit. It is only required for macOS Catalyst app-specific code.

    (more…)
  • Get iOS, iPadOS and macOS app Versions and Build numbers programmatically.

    Get iOS, iPadOS and macOS app Versions and Build numbers programmatically.

    Here is a small function I have written that you can use in your iOS, iPadOS or macOS Catalyst app to get your app’s current version, build number, and print it on the screen whether it will be on the app’s about or support view.

    Copy the below function in the Xcode project’s UIViewController Swift class file.

    (more…)
  • Reset the Bluetooth module using the Terminal app on your Mac.

    Reset the Bluetooth module using the Terminal app on your Mac.

    Here is the simplest way to reset the Bluetooth module on your Mac if you face any issues using your Bluetooth mouse (Magic Mouse) or Bluetooth keyboard (Magic Keyboard).

    This command will reset Bluetooth on your Mac and then connect to all Bluetooth devices again after the reset.

    Step 01:
    Open the Terminal app from your Mac’s Applications > Utility folder.

    Step 02:
    Now copy-paste the below command in the terminal to reset Bluetooth on your Mac

    (more…)
  • Implementing Meta Theme Color modern HTML5 and CSS3 websites.

    Apple Safari has started supporting theme-color Meta Tag from the Safari 15 release.

    Here is how to Implement a theme-color meta tag in HTML.

    You have to copy-paste the theme-color meta tag into a section of your website. It will look something like this:

    <meta name="theme-color" content="#ff0000"/>

    You can use the following code to implement theme color specific to system light or dark modes.

    <meta name="theme-color" content="#ff0000" media="(prefers-color-scheme: light)">
    <meta name="theme-color" content="#ff0000" media="(prefers-color-scheme: dark)">
    (more…)
  • Find the Bundle ID of any app on Mac.

    There are many ways to identify the bundle ID of any macOS app using the Mac itself.

    The following steps will help you identify a Finder app’s bundle ID using the Terminal. Replace the app name written in step 02 with the exact words of your desired app name.

    Step 01:
    Open Terminal on your Mac.

    Step 02:
    Run the following command:

    (more…)
  • Essential factors to be considered while choosing UILabel and UITextView to display text for iOS, iPadOS and macOS apps.

    Choosing between UILabel and UITextView starts when you want to display text in your Apple iOS, iPadOS or macOS Catalyst App.

    I have even gone through the process of choosing UILabel or UITextView to display text on my app.

    So, I have made a small numbered list to help you choose the right option…

    Choose UILable to display text:

    1. If the text word count is small in number
    2. If Top Aligning text to the top border is not the requirement
    3. UILable is not tappable interactive, or selectable to the user’s input
    4. if you want to automatically adjust the font size and fit text to the UILabel bounding box layout

    Here is a Sample Code for UILabel:

    (more…)

Sponsors


Search